1 | /* |
---|
2 | * Author : Gérald FENOY |
---|
3 | * |
---|
4 | * Copyright (c) 2009-2015 GeoLabs SARL |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "response_print.h" |
---|
26 | #include "request_parser.h" |
---|
27 | #include "server_internal.h" |
---|
28 | #include "service_internal.h" |
---|
29 | #ifdef USE_MS |
---|
30 | #include "service_internal_ms.h" |
---|
31 | #else |
---|
32 | #include "cpl_vsi.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | #ifndef TRUE |
---|
36 | #define TRUE 1 |
---|
37 | #endif |
---|
38 | #ifndef FALSE |
---|
39 | #define FALSE -1 |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifndef WIN32 |
---|
43 | #include <dlfcn.h> |
---|
44 | #endif |
---|
45 | |
---|
46 | #include "mimetypes.h" |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | * Add prefix to the service name. |
---|
51 | * |
---|
52 | * @param conf the conf maps containing the main.cfg settings |
---|
53 | * @param level the map containing the level information |
---|
54 | * @param serv the service structure created from the zcfg file |
---|
55 | */ |
---|
56 | void addPrefix(maps* conf,map* level,service* serv){ |
---|
57 | if(level!=NULL){ |
---|
58 | char key[25]; |
---|
59 | char* prefix=NULL; |
---|
60 | int clevel=atoi(level->value); |
---|
61 | int cl=0; |
---|
62 | for(cl=0;cl<clevel;cl++){ |
---|
63 | sprintf(key,"sprefix_%d",cl); |
---|
64 | map* tmp2=getMapFromMaps(conf,"lenv",key); |
---|
65 | if(tmp2!=NULL){ |
---|
66 | if(prefix==NULL) |
---|
67 | prefix=zStrdup(tmp2->value); |
---|
68 | else{ |
---|
69 | int plen=strlen(prefix); |
---|
70 | prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char)); |
---|
71 | memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char)); |
---|
72 | prefix[plen+strlen(tmp2->value)]=0; |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|
76 | if(prefix!=NULL){ |
---|
77 | char* tmp0=strdup(serv->name); |
---|
78 | free(serv->name); |
---|
79 | serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); |
---|
80 | sprintf(serv->name,"%s%s",prefix,tmp0); |
---|
81 | free(tmp0); |
---|
82 | free(prefix); |
---|
83 | prefix=NULL; |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Print the HTTP headers based on a map. |
---|
90 | * |
---|
91 | * @param m the map containing the headers informations |
---|
92 | */ |
---|
93 | void printHeaders(maps* m){ |
---|
94 | maps *_tmp=getMaps(m,"headers"); |
---|
95 | if(_tmp!=NULL){ |
---|
96 | map* _tmp1=_tmp->content; |
---|
97 | while(_tmp1!=NULL){ |
---|
98 | printf("%s: %s\r\n",_tmp1->name,_tmp1->value); |
---|
99 | _tmp1=_tmp1->next; |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * Add a land attribute to a XML node |
---|
106 | * |
---|
107 | * @param n the XML node to add the attribute |
---|
108 | * @param m the map containing the language key to add as xml:lang |
---|
109 | */ |
---|
110 | void addLangAttr(xmlNodePtr n,maps *m){ |
---|
111 | map *tmpLmap=getMapFromMaps(m,"main","language"); |
---|
112 | if(tmpLmap!=NULL) |
---|
113 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value); |
---|
114 | else |
---|
115 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US"); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Replace the first letter by its upper case version in a new char array |
---|
120 | * |
---|
121 | * @param tmp the char* |
---|
122 | * @return a new char* with first letter in upper case |
---|
123 | * @warning be sure to free() the returned string after use |
---|
124 | */ |
---|
125 | char *zCapitalize1(char *tmp){ |
---|
126 | char *res=zStrdup(tmp); |
---|
127 | if(res[0]>=97 && res[0]<=122) |
---|
128 | res[0]-=32; |
---|
129 | return res; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * Replace all letters by their upper case version in a new char array |
---|
134 | * |
---|
135 | * @param tmp the char* |
---|
136 | * @return a new char* with first letter in upper case |
---|
137 | * @warning be sure to free() the returned string after use |
---|
138 | */ |
---|
139 | char *zCapitalize(char *tmp){ |
---|
140 | int i=0; |
---|
141 | char *res=zStrdup(tmp); |
---|
142 | for(i=0;i<strlen(res);i++) |
---|
143 | if(res[i]>=97 && res[i]<=122) |
---|
144 | res[i]-=32; |
---|
145 | return res; |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * Search for an existing XML namespace in usedNS. |
---|
150 | * |
---|
151 | * @param name the name of the XML namespace to search |
---|
152 | * @return the index of the XML namespace found or -1 if not found. |
---|
153 | */ |
---|
154 | int zooXmlSearchForNs(const char* name){ |
---|
155 | int i; |
---|
156 | int res=-1; |
---|
157 | for(i=0;i<nbNs;i++) |
---|
158 | if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){ |
---|
159 | res=i; |
---|
160 | break; |
---|
161 | } |
---|
162 | return res; |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Add an XML namespace to the usedNS if it was not already used. |
---|
167 | * |
---|
168 | * @param nr the xmlNodePtr to attach the XML namspace (can be NULL) |
---|
169 | * @param url the url of the XML namespace to add |
---|
170 | * @param name the name of the XML namespace to add |
---|
171 | * @return the index of the XML namespace added. |
---|
172 | */ |
---|
173 | int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){ |
---|
174 | #ifdef DEBUG |
---|
175 | fprintf(stderr,"zooXmlAddNs %d %s \n",nbNs,name); |
---|
176 | #endif |
---|
177 | int currId=-1; |
---|
178 | if(nbNs==0){ |
---|
179 | nbNs++; |
---|
180 | currId=0; |
---|
181 | nsName[currId]=strdup(name); |
---|
182 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
183 | }else{ |
---|
184 | currId=zooXmlSearchForNs(name); |
---|
185 | if(currId<0){ |
---|
186 | nbNs++; |
---|
187 | currId=nbNs-1; |
---|
188 | nsName[currId]=strdup(name); |
---|
189 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
190 | } |
---|
191 | } |
---|
192 | return currId; |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Free allocated memory to store used XML namespace. |
---|
197 | */ |
---|
198 | void zooXmlCleanupNs(){ |
---|
199 | int j; |
---|
200 | #ifdef DEBUG |
---|
201 | fprintf(stderr,"zooXmlCleanup %d\n",nbNs); |
---|
202 | #endif |
---|
203 | for(j=nbNs-1;j>=0;j--){ |
---|
204 | #ifdef DEBUG |
---|
205 | fprintf(stderr,"zooXmlCleanup %d\n",j); |
---|
206 | #endif |
---|
207 | if(j==0) |
---|
208 | xmlFreeNs(usedNs[j]); |
---|
209 | free(nsName[j]); |
---|
210 | nbNs--; |
---|
211 | } |
---|
212 | nbNs=0; |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * Add a XML document to the iDocs. |
---|
217 | * |
---|
218 | * @param value the string containing the XML document |
---|
219 | * @return the index of the XML document added. |
---|
220 | */ |
---|
221 | int zooXmlAddDoc(const char* value){ |
---|
222 | int currId=0; |
---|
223 | nbDocs++; |
---|
224 | currId=nbDocs-1; |
---|
225 | iDocs[currId]=xmlParseMemory(value,strlen(value)); |
---|
226 | return currId; |
---|
227 | } |
---|
228 | |
---|
229 | /** |
---|
230 | * Free allocated memort to store XML documents |
---|
231 | */ |
---|
232 | void zooXmlCleanupDocs(){ |
---|
233 | int j; |
---|
234 | for(j=nbDocs-1;j>=0;j--){ |
---|
235 | xmlFreeDoc(iDocs[j]); |
---|
236 | } |
---|
237 | nbDocs=0; |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * Generate a SOAP Envelope node when required (if the isSoap key of the [main] |
---|
242 | * section is set to true). |
---|
243 | * |
---|
244 | * @param conf the conf maps containing the main.cfg settings |
---|
245 | * @param n the node used as children of the generated soap:Envelope |
---|
246 | * @return the generated soap:Envelope (if isSoap=true) or the input node n |
---|
247 | * (when isSoap=false) |
---|
248 | */ |
---|
249 | xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){ |
---|
250 | map* soap=getMapFromMaps(conf,"main","isSoap"); |
---|
251 | if(soap!=NULL && strcasecmp(soap->value,"true")==0){ |
---|
252 | int lNbNs=nbNs; |
---|
253 | nsName[lNbNs]=strdup("soap"); |
---|
254 | usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); |
---|
255 | nbNs++; |
---|
256 | xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); |
---|
257 | nsName[nbNs]=strdup("soap"); |
---|
258 | usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); |
---|
259 | nbNs++; |
---|
260 | nsName[nbNs]=strdup("xsi"); |
---|
261 | usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); |
---|
262 | nbNs++; |
---|
263 | xmlNsPtr ns_xsi=usedNs[nbNs-1]; |
---|
264 | xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope"); |
---|
265 | xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body"); |
---|
266 | xmlAddChild(nr1,n); |
---|
267 | xmlAddChild(nr,nr1); |
---|
268 | return nr; |
---|
269 | }else |
---|
270 | return n; |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | * Generate a WPS header. |
---|
275 | * |
---|
276 | * @param doc the document to add the header |
---|
277 | * @param m the conf maps containing the main.cfg settings |
---|
278 | * @param req the request type (GetCapabilities,DescribeProcess,Execute) |
---|
279 | * @param rname the root node name |
---|
280 | * @return the generated wps:rname xmlNodePtr (can be wps: Capabilities, |
---|
281 | * wps:ProcessDescriptions,wps:ExecuteResponse) |
---|
282 | */ |
---|
283 | xmlNodePtr printWPSHeader(xmlDocPtr doc,maps* m,const char* req,const char* rname,const char* version,int reqId){ |
---|
284 | |
---|
285 | xmlNsPtr ns,ns_xsi; |
---|
286 | xmlNodePtr n; |
---|
287 | |
---|
288 | int vid=getVersionId(version); |
---|
289 | |
---|
290 | int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps"); |
---|
291 | ns=usedNs[wpsId]; |
---|
292 | n = xmlNewNode(ns, BAD_CAST rname); |
---|
293 | zooXmlAddNs(n,schemas[vid][1],"ows"); |
---|
294 | xmlNewNs(n,BAD_CAST schemas[vid][2],BAD_CAST "wps"); |
---|
295 | zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
296 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
297 | ns_xsi=usedNs[xsiId]; |
---|
298 | char *tmp=(char*) malloc((86+strlen(req)+1)*sizeof(char)); |
---|
299 | sprintf(tmp,schemas[vid][4],schemas[vid][2],schemas[vid][3],req); |
---|
300 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp); |
---|
301 | free(tmp); |
---|
302 | if(vid==0 || reqId==0){ |
---|
303 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
304 | xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][0]); |
---|
305 | } |
---|
306 | if(vid==0) |
---|
307 | addLangAttr(n,m); |
---|
308 | xmlNodePtr fn=soapEnvelope(m,n); |
---|
309 | xmlDocSetRootElement(doc, fn); |
---|
310 | return n; |
---|
311 | } |
---|
312 | |
---|
313 | void addLanguageNodes(maps* conf,xmlNodePtr n,xmlNsPtr ns,xmlNsPtr ns_ows){ |
---|
314 | xmlNodePtr nc1,nc2,nc3,nc4; |
---|
315 | map* version=getMapFromMaps(conf,"main","rversion"); |
---|
316 | int vid=getVersionId(version->value); |
---|
317 | if(vid==1) |
---|
318 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Languages"); |
---|
319 | else{ |
---|
320 | nc1 = xmlNewNode(ns, BAD_CAST "Languages"); |
---|
321 | nc2 = xmlNewNode(ns, BAD_CAST "Default"); |
---|
322 | nc3 = xmlNewNode(ns, BAD_CAST "Supported"); |
---|
323 | } |
---|
324 | |
---|
325 | maps* tmp=getMaps(conf,"main"); |
---|
326 | if(tmp!=NULL){ |
---|
327 | map* tmp1=getMap(tmp->content,"lang"); |
---|
328 | char *toto=tmp1->value; |
---|
329 | char buff[256]; |
---|
330 | int i=0; |
---|
331 | int j=0; |
---|
332 | int dcount=0; |
---|
333 | while(toto[i]){ |
---|
334 | if(toto[i]!=',' && toto[i]!=0){ |
---|
335 | buff[j]=toto[i]; |
---|
336 | buff[j+1]=0; |
---|
337 | j++; |
---|
338 | } |
---|
339 | else{ |
---|
340 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
341 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
342 | if(dcount==0){ |
---|
343 | if(vid==0){ |
---|
344 | xmlAddChild(nc2,nc4); |
---|
345 | xmlAddChild(nc1,nc2); |
---|
346 | } |
---|
347 | dcount++; |
---|
348 | } |
---|
349 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
350 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
351 | if(vid==0) |
---|
352 | xmlAddChild(nc3,nc4); |
---|
353 | else |
---|
354 | xmlAddChild(nc1,nc4); |
---|
355 | j=0; |
---|
356 | buff[j]=0; |
---|
357 | } |
---|
358 | i++; |
---|
359 | } |
---|
360 | if(strlen(buff)>0){ |
---|
361 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
362 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
363 | if(vid==0) |
---|
364 | xmlAddChild(nc3,nc4); |
---|
365 | else |
---|
366 | xmlAddChild(nc1,nc4); |
---|
367 | } |
---|
368 | } |
---|
369 | if(vid==0) |
---|
370 | xmlAddChild(nc1,nc3); |
---|
371 | xmlAddChild(n,nc1); |
---|
372 | } |
---|
373 | |
---|
374 | /** |
---|
375 | * Generate a Capabilities header. |
---|
376 | * |
---|
377 | * @param doc the document to add the header |
---|
378 | * @param m the conf maps containing the main.cfg settings |
---|
379 | * @return the generated wps:ProcessOfferings xmlNodePtr |
---|
380 | */ |
---|
381 | xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,maps* m,const char* version="1.0.0"){ |
---|
382 | |
---|
383 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
384 | xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6; |
---|
385 | n = printWPSHeader(doc,m,"GetCapabilities","Capabilities",version,0); |
---|
386 | maps* toto1=getMaps(m,"main"); |
---|
387 | char tmp[256]; |
---|
388 | map* v=getMapFromMaps(m,"main","rversion"); |
---|
389 | int vid=getVersionId(v->value); |
---|
390 | |
---|
391 | int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps"); |
---|
392 | ns=usedNs[wpsId]; |
---|
393 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
394 | ns_xlink=usedNs[xlinkId]; |
---|
395 | int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows"); |
---|
396 | ns_ows=usedNs[owsId]; |
---|
397 | |
---|
398 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); |
---|
399 | maps* tmp4=getMaps(m,"identification"); |
---|
400 | if(tmp4!=NULL){ |
---|
401 | map* tmp2=tmp4->content; |
---|
402 | const char *orderedFields[5]; |
---|
403 | orderedFields[0]="Title"; |
---|
404 | orderedFields[1]="Abstract"; |
---|
405 | orderedFields[2]="Keywords"; |
---|
406 | orderedFields[3]="Fees"; |
---|
407 | orderedFields[4]="AccessConstraints"; |
---|
408 | int oI=0; |
---|
409 | for(oI=0;oI<5;oI++) |
---|
410 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
411 | if(strcasecmp(tmp2->name,"abstract")==0 || |
---|
412 | strcasecmp(tmp2->name,"title")==0 || |
---|
413 | strcasecmp(tmp2->name,"accessConstraints")==0 || |
---|
414 | strcasecmp(tmp2->name,"fees")==0){ |
---|
415 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
416 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
417 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
418 | xmlAddChild(nc,nc1); |
---|
419 | } |
---|
420 | else |
---|
421 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
422 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
423 | char *toto=tmp2->value; |
---|
424 | char buff[256]; |
---|
425 | int i=0; |
---|
426 | int j=0; |
---|
427 | while(toto[i]){ |
---|
428 | if(toto[i]!=',' && toto[i]!=0){ |
---|
429 | buff[j]=toto[i]; |
---|
430 | buff[j+1]=0; |
---|
431 | j++; |
---|
432 | } |
---|
433 | else{ |
---|
434 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
435 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
436 | xmlAddChild(nc1,nc2); |
---|
437 | j=0; |
---|
438 | } |
---|
439 | i++; |
---|
440 | } |
---|
441 | if(strlen(buff)>0){ |
---|
442 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
443 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
444 | xmlAddChild(nc1,nc2); |
---|
445 | } |
---|
446 | xmlAddChild(nc,nc1); |
---|
447 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); |
---|
448 | xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); |
---|
449 | xmlAddChild(nc,nc2); |
---|
450 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); |
---|
451 | map* tmpv=getMapFromMaps(m,"main","rversion"); |
---|
452 | xmlAddChild(nc2,xmlNewText(BAD_CAST tmpv->value)); |
---|
453 | xmlAddChild(nc,nc2); |
---|
454 | } |
---|
455 | tmp2=tmp2->next; |
---|
456 | } |
---|
457 | } |
---|
458 | else{ |
---|
459 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
460 | return NULL; |
---|
461 | } |
---|
462 | xmlAddChild(n,nc); |
---|
463 | |
---|
464 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); |
---|
465 | nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); |
---|
466 | nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); |
---|
467 | nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); |
---|
468 | nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); |
---|
469 | tmp4=getMaps(m,"provider"); |
---|
470 | if(tmp4!=NULL){ |
---|
471 | map* tmp2=tmp4->content; |
---|
472 | const char *tmpAddress[6]; |
---|
473 | tmpAddress[0]="addressDeliveryPoint"; |
---|
474 | tmpAddress[1]="addressCity"; |
---|
475 | tmpAddress[2]="addressAdministrativeArea"; |
---|
476 | tmpAddress[3]="addressPostalCode"; |
---|
477 | tmpAddress[4]="addressCountry"; |
---|
478 | tmpAddress[5]="addressElectronicMailAddress"; |
---|
479 | const char *tmpPhone[2]; |
---|
480 | tmpPhone[0]="phoneVoice"; |
---|
481 | tmpPhone[1]="phoneFacsimile"; |
---|
482 | const char *orderedFields[12]; |
---|
483 | orderedFields[0]="providerName"; |
---|
484 | orderedFields[1]="providerSite"; |
---|
485 | orderedFields[2]="individualName"; |
---|
486 | orderedFields[3]="positionName"; |
---|
487 | orderedFields[4]=tmpPhone[0]; |
---|
488 | orderedFields[5]=tmpPhone[1]; |
---|
489 | orderedFields[6]=tmpAddress[0]; |
---|
490 | orderedFields[7]=tmpAddress[1]; |
---|
491 | orderedFields[8]=tmpAddress[2]; |
---|
492 | orderedFields[9]=tmpAddress[3]; |
---|
493 | orderedFields[10]=tmpAddress[4]; |
---|
494 | orderedFields[11]=tmpAddress[5]; |
---|
495 | int oI=0; |
---|
496 | for(oI=0;oI<12;oI++) |
---|
497 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
498 | if(strcmp(tmp2->name,"keywords")!=0 && |
---|
499 | strcmp(tmp2->name,"serverAddress")!=0 && |
---|
500 | strcmp(tmp2->name,"lang")!=0){ |
---|
501 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
502 | if(strcmp(tmp2->name,"ProviderName")==0){ |
---|
503 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
504 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
505 | xmlAddChild(nc,nc1); |
---|
506 | } |
---|
507 | else{ |
---|
508 | if(strcmp(tmp2->name,"ProviderSite")==0){ |
---|
509 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
510 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); |
---|
511 | xmlAddChild(nc,nc1); |
---|
512 | } |
---|
513 | else |
---|
514 | if(strcmp(tmp2->name,"IndividualName")==0 || |
---|
515 | strcmp(tmp2->name,"PositionName")==0){ |
---|
516 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
517 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
518 | xmlAddChild(nc3,nc1); |
---|
519 | } |
---|
520 | else |
---|
521 | if(strncmp(tmp2->name,"Phone",5)==0){ |
---|
522 | int j; |
---|
523 | for(j=0;j<2;j++) |
---|
524 | if(strcasecmp(tmp2->name,tmpPhone[j])==0){ |
---|
525 | char *tmp4=tmp2->name; |
---|
526 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+5); |
---|
527 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
528 | xmlAddChild(nc5,nc1); |
---|
529 | } |
---|
530 | } |
---|
531 | else |
---|
532 | if(strncmp(tmp2->name,"Address",7)==0){ |
---|
533 | int j; |
---|
534 | for(j=0;j<6;j++) |
---|
535 | if(strcasecmp(tmp2->name,tmpAddress[j])==0){ |
---|
536 | char *tmp4=tmp2->name; |
---|
537 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+7); |
---|
538 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
539 | xmlAddChild(nc6,nc1); |
---|
540 | } |
---|
541 | } |
---|
542 | } |
---|
543 | } |
---|
544 | else |
---|
545 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
546 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
547 | char *toto=tmp2->value; |
---|
548 | char buff[256]; |
---|
549 | int i=0; |
---|
550 | int j=0; |
---|
551 | while(toto[i]){ |
---|
552 | if(toto[i]!=',' && toto[i]!=0){ |
---|
553 | buff[j]=toto[i]; |
---|
554 | buff[j+1]=0; |
---|
555 | j++; |
---|
556 | } |
---|
557 | else{ |
---|
558 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
559 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
560 | xmlAddChild(nc1,nc2); |
---|
561 | j=0; |
---|
562 | } |
---|
563 | i++; |
---|
564 | } |
---|
565 | if(strlen(buff)>0){ |
---|
566 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
567 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
568 | xmlAddChild(nc1,nc2); |
---|
569 | } |
---|
570 | xmlAddChild(nc,nc1); |
---|
571 | } |
---|
572 | tmp2=tmp2->next; |
---|
573 | } |
---|
574 | } |
---|
575 | else{ |
---|
576 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
577 | } |
---|
578 | xmlAddChild(nc4,nc5); |
---|
579 | xmlAddChild(nc4,nc6); |
---|
580 | xmlAddChild(nc3,nc4); |
---|
581 | xmlAddChild(nc,nc3); |
---|
582 | xmlAddChild(n,nc); |
---|
583 | |
---|
584 | |
---|
585 | nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); |
---|
586 | |
---|
587 | int j=0; |
---|
588 | |
---|
589 | if(toto1!=NULL){ |
---|
590 | map* tmp=getMap(toto1->content,"serverAddress"); |
---|
591 | if(tmp!=NULL){ |
---|
592 | SERVICE_URL = strdup(tmp->value); |
---|
593 | } |
---|
594 | else |
---|
595 | SERVICE_URL = strdup("not_defined"); |
---|
596 | } |
---|
597 | else |
---|
598 | SERVICE_URL = strdup("not_defined"); |
---|
599 | |
---|
600 | for(j=0;j<nbSupportedRequests;j++){ |
---|
601 | if(requests[vid][j]==NULL) |
---|
602 | break; |
---|
603 | else{ |
---|
604 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); |
---|
605 | xmlNewProp(nc1,BAD_CAST "name",BAD_CAST requests[vid][j]); |
---|
606 | nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); |
---|
607 | nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); |
---|
608 | if(vid!=1 || j!=2){ |
---|
609 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); |
---|
610 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST SERVICE_URL); |
---|
611 | xmlAddChild(nc3,nc4); |
---|
612 | } |
---|
613 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); |
---|
614 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST SERVICE_URL); |
---|
615 | xmlAddChild(nc3,nc4); |
---|
616 | xmlAddChild(nc2,nc3); |
---|
617 | xmlAddChild(nc1,nc2); |
---|
618 | xmlAddChild(nc,nc1); |
---|
619 | } |
---|
620 | } |
---|
621 | xmlAddChild(n,nc); |
---|
622 | |
---|
623 | if(vid==1) |
---|
624 | addLanguageNodes(m,n,ns,ns_ows); |
---|
625 | free(SERVICE_URL); |
---|
626 | |
---|
627 | nc = xmlNewNode(ns, BAD_CAST root_nodes[vid][0]); |
---|
628 | xmlAddChild(n,nc); |
---|
629 | |
---|
630 | if(vid==0) |
---|
631 | addLanguageNodes(m,n,ns,ns_ows); |
---|
632 | |
---|
633 | return nc; |
---|
634 | } |
---|
635 | |
---|
636 | /** |
---|
637 | * Generate a wps:Process node for a servie and add it to a given node. |
---|
638 | * |
---|
639 | * @param reg the profiles registry |
---|
640 | * @param m the conf maps containing the main.cfg settings |
---|
641 | * @param registry the profile registry if any |
---|
642 | * @param nc the XML node to add the Process node |
---|
643 | * @param serv the service structure created from the zcfg file |
---|
644 | * @return the generated wps:ProcessOfferings xmlNodePtr |
---|
645 | */ |
---|
646 | void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){ |
---|
647 | xmlNsPtr ns,ns_ows,ns_xml,ns_xlink; |
---|
648 | xmlNodePtr n=NULL,nc1,nc2; |
---|
649 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
650 | int vid=getVersionId(version->value); |
---|
651 | // Initialize or get existing namespaces |
---|
652 | int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps"); |
---|
653 | ns=usedNs[wpsId]; |
---|
654 | int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows"); |
---|
655 | ns_ows=usedNs[owsId]; |
---|
656 | int xmlId=zooXmlAddNs(NULL,"http://www.w3.org/XML/1998/namespace","xml"); |
---|
657 | ns_xml=usedNs[xmlId]; |
---|
658 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
659 | ns_xlink=usedNs[xlinkId]; |
---|
660 | map* tmp1; |
---|
661 | if(serv->content!=NULL){ |
---|
662 | nc1 = xmlNewNode(ns, BAD_CAST capabilities[vid][0]); |
---|
663 | int i=1; |
---|
664 | int limit=3; |
---|
665 | if(vid==1){ |
---|
666 | ns=NULL; |
---|
667 | limit=7; |
---|
668 | } |
---|
669 | for(;i<limit;i+=2){ |
---|
670 | if(capabilities[vid][i]==NULL) |
---|
671 | break; |
---|
672 | else{ |
---|
673 | tmp1=getMap(serv->content,capabilities[vid][i]); |
---|
674 | if(tmp1!=NULL){ |
---|
675 | if(vid==1 && i==1 && strlen(tmp1->value)<5){ |
---|
676 | char *val=(char*)malloc((strlen(tmp1->value)+5)*sizeof(char)); |
---|
677 | sprintf(val,"%s.0.0",tmp1->value); |
---|
678 | xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST val); |
---|
679 | free(val); |
---|
680 | } |
---|
681 | else |
---|
682 | xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value); |
---|
683 | } |
---|
684 | else |
---|
685 | xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); |
---|
686 | } |
---|
687 | } |
---|
688 | map* tmp3=getMapFromMaps(m,"lenv","level"); |
---|
689 | addPrefix(m,tmp3,serv); |
---|
690 | printDescription(nc1,ns_ows,serv->name,serv->content,vid); |
---|
691 | 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 | |
---|
699 | xmlAddChild(nc,nc1); |
---|
700 | } |
---|
701 | } |
---|
702 | |
---|
703 | /** |
---|
704 | * Attach attributes to a ProcessDescription or a ProcessOffering node. |
---|
705 | * |
---|
706 | * @param n the XML node to attach the attributes to |
---|
707 | * @param ns the XML namespace to create the attributes |
---|
708 | * @param content the servive main content created from the zcfg file |
---|
709 | * @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){ |
---|
712 | int limit=(vid==1?7:3); |
---|
713 | for(int i=1;i<limit;i+=2){ |
---|
714 | map* tmp1=getMap(content,capabilities[vid][i]); |
---|
715 | if(tmp1!=NULL){ |
---|
716 | if(vid==1 && i==1 && strlen(tmp1->value)<5){ |
---|
717 | char *val=(char*)malloc((strlen(tmp1->value)+5)*sizeof(char)); |
---|
718 | sprintf(val,"%s.0.0",tmp1->value); |
---|
719 | xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST val); |
---|
720 | free(val); |
---|
721 | } |
---|
722 | else |
---|
723 | xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value); |
---|
724 | } |
---|
725 | else |
---|
726 | xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); |
---|
727 | } |
---|
728 | } |
---|
729 | |
---|
730 | /** |
---|
731 | * Add the ows:Metadata nodes relative to the profile registry |
---|
732 | * |
---|
733 | * @param n the XML node to add the ows:Metadata |
---|
734 | * @param ns_ows the ows XML namespace |
---|
735 | * @param ns_xlink the ows xlink namespace |
---|
736 | * @param reg the profile registry |
---|
737 | * @param main_conf the map containing the main configuration content |
---|
738 | * @param serv the service |
---|
739 | */ |
---|
740 | void addInheritedMetadata(xmlNodePtr n,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,registry* reg,maps* main_conf,service* serv){ |
---|
741 | int vid=1; |
---|
742 | map* tmp1=getMap(serv->content,"extend"); |
---|
743 | if(tmp1==NULL) |
---|
744 | tmp1=getMap(serv->content,"concept"); |
---|
745 | if(tmp1!=NULL){ |
---|
746 | map* level=getMap(serv->content,"level"); |
---|
747 | if(level!=NULL){ |
---|
748 | xmlNodePtr nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
749 | char* ckey=level->value; |
---|
750 | if(strncasecmp(level->value,"profile",7)==0) |
---|
751 | ckey="generic"; |
---|
752 | if(strncasecmp(level->value,"generic",7)==0) |
---|
753 | ckey="concept"; |
---|
754 | service* inherited=getServiceFromRegistry(reg,ckey,tmp1->value); |
---|
755 | if(inherited!=NULL){ |
---|
756 | addInheritedMetadata(n,ns_ows,ns_xlink,reg,main_conf,inherited); |
---|
757 | } |
---|
758 | char cschema[71]; |
---|
759 | sprintf(cschema,"%s%s",schemas[vid][7],ckey); |
---|
760 | map* regUrl=getMapFromMaps(main_conf,"main","registryUrl"); |
---|
761 | map* regExt=getMapFromMaps(main_conf,"main","registryExt"); |
---|
762 | char* registryUrl=(char*)malloc((strlen(regUrl->value)+strlen(ckey)+ |
---|
763 | (regExt!=NULL?strlen(regExt->value)+1:0)+ |
---|
764 | strlen(tmp1->value)+2)*sizeof(char)); |
---|
765 | if(regExt!=NULL) |
---|
766 | sprintf(registryUrl,"%s%s/%s.%s",regUrl->value,ckey,tmp1->value,regExt->value); |
---|
767 | else |
---|
768 | sprintf(registryUrl,"%s%s/%s",regUrl->value,ckey,tmp1->value); |
---|
769 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "role",BAD_CAST cschema); |
---|
770 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST registryUrl); |
---|
771 | free(registryUrl); |
---|
772 | xmlAddChild(n,nc1); |
---|
773 | } |
---|
774 | } |
---|
775 | } |
---|
776 | |
---|
777 | /** |
---|
778 | * Generate a ProcessDescription node for a servie and add it to a given node. |
---|
779 | * |
---|
780 | * @param reg the profile registry |
---|
781 | * @param m the conf maps containing the main.cfg settings |
---|
782 | * @param nc the XML node to add the Process node |
---|
783 | * @param serv the servive structure created from the zcfg file |
---|
784 | * @return the generated wps:ProcessOfferings xmlNodePtr |
---|
785 | */ |
---|
786 | void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){ |
---|
787 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
788 | xmlNodePtr n,nc1,nc2; |
---|
789 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
790 | int vid=getVersionId(version->value); |
---|
791 | |
---|
792 | n=nc; |
---|
793 | |
---|
794 | int wpsId=zooXmlAddNs(NULL,schemas[vid][3],"wps"); |
---|
795 | ns=usedNs[wpsId]; |
---|
796 | int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows"); |
---|
797 | ns_ows=usedNs[owsId]; |
---|
798 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
799 | ns_xlink=usedNs[xlinkId]; |
---|
800 | map* tmp1=NULL; |
---|
801 | |
---|
802 | if(vid==0){ |
---|
803 | nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); |
---|
804 | attachAttributes(nc,ns,serv->content,vid); |
---|
805 | } |
---|
806 | else{ |
---|
807 | nc2 = xmlNewNode(ns, BAD_CAST "ProcessOffering"); |
---|
808 | // In case mode was defined in the ZCFG file then restrict the |
---|
809 | // jobControlOptions value to this value. The dismiss is always |
---|
810 | // supported whatever you can set in the ZCFG file. |
---|
811 | // cf. http://docs.opengeospatial.org/is/14-065/14-065.html#47 (Table 30) |
---|
812 | map* mode=getMap(serv->content,"mode"); |
---|
813 | if(mode!=NULL){ |
---|
814 | if( strncasecmp(mode->value,"sync",strlen(mode->value))==0 || |
---|
815 | strncasecmp(mode->value,"async",strlen(mode->value))==0 ){ |
---|
816 | char toReplace[22]; |
---|
817 | sprintf(toReplace,"%s-execute dismiss",mode->value); |
---|
818 | addToMap(serv->content,capabilities[vid][3],toReplace); |
---|
819 | } |
---|
820 | } |
---|
821 | attachAttributes(nc2,NULL,serv->content,vid); |
---|
822 | map* level=getMap(serv->content,"level"); |
---|
823 | if(level!=NULL && strcasecmp(level->value,"generic")==0) |
---|
824 | nc = xmlNewNode(ns, BAD_CAST "GenericProcess"); |
---|
825 | else |
---|
826 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
827 | } |
---|
828 | |
---|
829 | tmp1=getMapFromMaps(m,"lenv","level"); |
---|
830 | addPrefix(m,tmp1,serv); |
---|
831 | printDescription(nc,ns_ows,serv->name,serv->content,vid); |
---|
832 | |
---|
833 | if(vid==0){ |
---|
834 | tmp1=serv->metadata; |
---|
835 | while(tmp1!=NULL){ |
---|
836 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
837 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
838 | xmlAddChild(nc,nc1); |
---|
839 | tmp1=tmp1->next; |
---|
840 | } |
---|
841 | tmp1=getMap(serv->content,"Profile"); |
---|
842 | if(tmp1!=NULL && vid==0){ |
---|
843 | nc1 = xmlNewNode(ns, BAD_CAST "Profile"); |
---|
844 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); |
---|
845 | xmlAddChild(nc,nc1); |
---|
846 | } |
---|
847 | }else{ |
---|
848 | addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv); |
---|
849 | } |
---|
850 | |
---|
851 | if(serv->inputs!=NULL){ |
---|
852 | elements* e=serv->inputs; |
---|
853 | if(vid==0){ |
---|
854 | nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); |
---|
855 | printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid); |
---|
856 | xmlAddChild(nc,nc1); |
---|
857 | } |
---|
858 | else{ |
---|
859 | printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid); |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | elements* e=serv->outputs; |
---|
864 | if(vid==0){ |
---|
865 | nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); |
---|
866 | printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid); |
---|
867 | xmlAddChild(nc,nc1); |
---|
868 | } |
---|
869 | else{ |
---|
870 | printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid); |
---|
871 | } |
---|
872 | if(vid==0) |
---|
873 | xmlAddChild(n,nc); |
---|
874 | else{ |
---|
875 | xmlAddChild(nc2,nc); |
---|
876 | xmlAddChild(n,nc2); |
---|
877 | } |
---|
878 | |
---|
879 | } |
---|
880 | |
---|
881 | /** |
---|
882 | * Generate the required XML tree for the detailled metadata informations of |
---|
883 | * inputs or outputs |
---|
884 | * |
---|
885 | * @param in 1 in case of inputs, 0 for outputs |
---|
886 | * @param elem the elements structure containing the metadata informations |
---|
887 | * @param type the name ("Input" or "Output") of the XML node to create |
---|
888 | * @param ns_ows the ows XML namespace |
---|
889 | * @param ns_ows the ows XML namespace |
---|
890 | * @param nc1 the XML node to use to add the created tree |
---|
891 | * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0) |
---|
892 | */ |
---|
893 | void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){ |
---|
894 | xmlNsPtr ns1=NULL; |
---|
895 | if(vid==1) |
---|
896 | ns1=ns; |
---|
897 | |
---|
898 | xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7,nc8,nc9; |
---|
899 | elements* e=elem; |
---|
900 | nc9=NULL; |
---|
901 | map* tmp1=NULL; |
---|
902 | while(e!=NULL){ |
---|
903 | int default1=0; |
---|
904 | int isAnyValue=1; |
---|
905 | nc2 = xmlNewNode(NULL, BAD_CAST type); |
---|
906 | if(strstr(type,"Input")!=NULL){ |
---|
907 | tmp1=getMap(e->content,"minOccurs"); |
---|
908 | if(tmp1!=NULL){ |
---|
909 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
910 | }else |
---|
911 | xmlNewProp(nc2,BAD_CAST "minOccurs",BAD_CAST "0"); |
---|
912 | tmp1=getMap(e->content,"maxOccurs"); |
---|
913 | if(tmp1!=NULL){ |
---|
914 | if(strcasecmp(tmp1->value,"unbounded")!=0) |
---|
915 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
916 | else |
---|
917 | xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1000"); |
---|
918 | }else |
---|
919 | xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1"); |
---|
920 | if((tmp1=getMap(e->content,"maximumMegabytes"))!=NULL){ |
---|
921 | xmlNewProp(nc2,BAD_CAST "maximumMegabytes",BAD_CAST tmp1->value); |
---|
922 | } |
---|
923 | } |
---|
924 | |
---|
925 | printDescription(nc2,ns_ows,e->name,e->content,vid); |
---|
926 | |
---|
927 | if(e->format!=NULL){ |
---|
928 | const char orderedFields[13][14]={ |
---|
929 | "mimeType", |
---|
930 | "encoding", |
---|
931 | "schema", |
---|
932 | "dataType", |
---|
933 | "uom", |
---|
934 | "CRS", |
---|
935 | "AllowedValues", |
---|
936 | "range", |
---|
937 | "rangeMin", |
---|
938 | "rangeMax", |
---|
939 | "rangeClosure", |
---|
940 | "rangeSpace" |
---|
941 | }; |
---|
942 | |
---|
943 | //Build the (Literal/Complex/BoundingBox)Data node |
---|
944 | if(strncmp(type,"Output",6)==0){ |
---|
945 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) |
---|
946 | nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput"); |
---|
947 | else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
948 | nc3 = xmlNewNode(ns1, BAD_CAST "ComplexOutput"); |
---|
949 | else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) |
---|
950 | nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxOutput"); |
---|
951 | else |
---|
952 | nc3 = xmlNewNode(ns1, BAD_CAST e->format); |
---|
953 | }else{ |
---|
954 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0 || |
---|
955 | strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0){ |
---|
956 | nc3 = xmlNewNode(ns1, BAD_CAST "LiteralData"); |
---|
957 | } |
---|
958 | else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
959 | nc3 = xmlNewNode(ns1, BAD_CAST "ComplexData"); |
---|
960 | else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) |
---|
961 | nc3 = xmlNewNode(ns1, BAD_CAST "BoundingBoxData"); |
---|
962 | else |
---|
963 | nc3 = xmlNewNode(ns1, BAD_CAST e->format); |
---|
964 | } |
---|
965 | |
---|
966 | iotype* _tmp0=NULL; |
---|
967 | iotype* _tmp=e->defaults; |
---|
968 | int datatype=0; |
---|
969 | bool hasUOM=false; |
---|
970 | bool hasUOM1=false; |
---|
971 | if(_tmp!=NULL){ |
---|
972 | if(strcmp(e->format,"LiteralOutput")==0 || |
---|
973 | strcmp(e->format,"LiteralData")==0){ |
---|
974 | datatype=1; |
---|
975 | if(vid==1){ |
---|
976 | nc4 = xmlNewNode(ns1, BAD_CAST "Format"); |
---|
977 | xmlNewProp(nc4,BAD_CAST "mimeType",BAD_CAST "text/plain"); |
---|
978 | xmlNewProp(nc4,BAD_CAST "default",BAD_CAST "true"); |
---|
979 | xmlAddChild(nc3,nc4); |
---|
980 | nc5 = xmlNewNode(NULL, BAD_CAST "LiteralDataDomain"); |
---|
981 | xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true"); |
---|
982 | } |
---|
983 | else{ |
---|
984 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
985 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
986 | } |
---|
987 | } |
---|
988 | else if(strcmp(e->format,"BoundingBoxOutput")==0 || |
---|
989 | strcmp(e->format,"BoundingBoxData")==0){ |
---|
990 | datatype=2; |
---|
991 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
992 | } |
---|
993 | else{ |
---|
994 | if(vid==0) |
---|
995 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
996 | nc5 = xmlNewNode(ns1, BAD_CAST "Format"); |
---|
997 | if(vid==1){ |
---|
998 | xmlNewProp(nc5,BAD_CAST "default",BAD_CAST "true"); |
---|
999 | int oI=0; |
---|
1000 | for(oI=0;oI<3;oI++) |
---|
1001 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
1002 | xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value); |
---|
1003 | } |
---|
1004 | } |
---|
1005 | } |
---|
1006 | |
---|
1007 | tmp1=_tmp->content; |
---|
1008 | |
---|
1009 | if(vid==0) |
---|
1010 | if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){ |
---|
1011 | nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
1012 | xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value)); |
---|
1013 | char tmp[1024]; |
---|
1014 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
1015 | xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
1016 | if(vid==0) |
---|
1017 | xmlAddChild(nc3,nc8); |
---|
1018 | else |
---|
1019 | xmlAddChild(nc5,nc8); |
---|
1020 | datatype=1; |
---|
1021 | } |
---|
1022 | |
---|
1023 | bool isInput=false; |
---|
1024 | if(strncmp(type,"Input",5)==0 || strncmp(type,"wps:Input",9)==0){ |
---|
1025 | isInput=true; |
---|
1026 | if((tmp1=getMap(_tmp->content,"AllowedValues"))!=NULL){ |
---|
1027 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
1028 | char *token,*saveptr1; |
---|
1029 | token=strtok_r(tmp1->value,",",&saveptr1); |
---|
1030 | while(token!=NULL){ |
---|
1031 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
1032 | char *tmps=strdup(token); |
---|
1033 | tmps[strlen(tmps)]=0; |
---|
1034 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); |
---|
1035 | free(tmps); |
---|
1036 | xmlAddChild(nc6,nc7); |
---|
1037 | token=strtok_r(NULL,",",&saveptr1); |
---|
1038 | } |
---|
1039 | if(getMap(_tmp->content,"range")!=NULL || |
---|
1040 | getMap(_tmp->content,"rangeMin")!=NULL || |
---|
1041 | getMap(_tmp->content,"rangeMax")!=NULL || |
---|
1042 | getMap(_tmp->content,"rangeClosure")!=NULL ) |
---|
1043 | goto doRange; |
---|
1044 | if(vid==0) |
---|
1045 | xmlAddChild(nc3,nc6); |
---|
1046 | else |
---|
1047 | xmlAddChild(nc5,nc6); |
---|
1048 | isAnyValue=-1; |
---|
1049 | } |
---|
1050 | |
---|
1051 | tmp1=getMap(_tmp->content,"range"); |
---|
1052 | if(tmp1==NULL) |
---|
1053 | tmp1=getMap(_tmp->content,"rangeMin"); |
---|
1054 | if(tmp1==NULL) |
---|
1055 | tmp1=getMap(_tmp->content,"rangeMax"); |
---|
1056 | |
---|
1057 | if(tmp1!=NULL && isAnyValue==1){ |
---|
1058 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
1059 | doRange: |
---|
1060 | |
---|
1061 | /** |
---|
1062 | * Range: Table 46 OGC Web Services Common Standard |
---|
1063 | */ |
---|
1064 | nc8 = xmlNewNode(ns_ows, BAD_CAST "Range"); |
---|
1065 | |
---|
1066 | map* tmp0=getMap(tmp1,"range"); |
---|
1067 | if(tmp0!=NULL){ |
---|
1068 | char* pToken; |
---|
1069 | char* orig=zStrdup(tmp0->value); |
---|
1070 | /** |
---|
1071 | * RangeClosure: Table 47 OGC Web Services Common Standard |
---|
1072 | */ |
---|
1073 | const char *tmp="closed"; |
---|
1074 | if(orig[0]=='[' && orig[strlen(orig)-1]=='[') |
---|
1075 | tmp="closed-open"; |
---|
1076 | else |
---|
1077 | if(orig[0]==']' && orig[strlen(orig)-1]==']') |
---|
1078 | tmp="open-closed"; |
---|
1079 | else |
---|
1080 | if(orig[0]==']' && orig[strlen(orig)-1]=='[') |
---|
1081 | tmp="open"; |
---|
1082 | xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp); |
---|
1083 | pToken=strtok(orig,","); |
---|
1084 | int nci0=0; |
---|
1085 | while(pToken!=NULL){ |
---|
1086 | char *tmpStr=(char*) malloc((strlen(pToken))*sizeof(char)); |
---|
1087 | if(nci0==0){ |
---|
1088 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); |
---|
1089 | strncpy( tmpStr, pToken+1, strlen(pToken)-1 ); |
---|
1090 | tmpStr[strlen(pToken)-1] = '\0'; |
---|
1091 | }else{ |
---|
1092 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); |
---|
1093 | const char* bkt; |
---|
1094 | if ( ( bkt = strchr(pToken, '[') ) != NULL || ( bkt = strchr(pToken, ']') ) != NULL ){ |
---|
1095 | strncpy( tmpStr, pToken, bkt - pToken ); |
---|
1096 | tmpStr[bkt - pToken] = '\0'; |
---|
1097 | } |
---|
1098 | } |
---|
1099 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr)); |
---|
1100 | free(tmpStr); |
---|
1101 | xmlAddChild(nc8,nc7); |
---|
1102 | nci0++; |
---|
1103 | pToken = strtok(NULL,","); |
---|
1104 | } |
---|
1105 | if(getMap(tmp1,"rangeSpacing")==NULL){ |
---|
1106 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing"); |
---|
1107 | xmlAddChild(nc7,xmlNewText(BAD_CAST "1")); |
---|
1108 | xmlAddChild(nc8,nc7); |
---|
1109 | } |
---|
1110 | free(orig); |
---|
1111 | }else{ |
---|
1112 | |
---|
1113 | tmp0=getMap(tmp1,"rangeMin"); |
---|
1114 | if(tmp0!=NULL){ |
---|
1115 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); |
---|
1116 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); |
---|
1117 | xmlAddChild(nc8,nc7); |
---|
1118 | }else{ |
---|
1119 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); |
---|
1120 | xmlAddChild(nc8,nc7); |
---|
1121 | } |
---|
1122 | tmp0=getMap(tmp1,"rangeMax"); |
---|
1123 | if(tmp0!=NULL){ |
---|
1124 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); |
---|
1125 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); |
---|
1126 | xmlAddChild(nc8,nc7); |
---|
1127 | }else{ |
---|
1128 | nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); |
---|
1129 | xmlAddChild(nc8,nc7); |
---|
1130 | } |
---|
1131 | tmp0=getMap(tmp1,"rangeSpacing"); |
---|
1132 | if(tmp0!=NULL){ |
---|
1133 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing"); |
---|
1134 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); |
---|
1135 | xmlAddChild(nc8,nc7); |
---|
1136 | } |
---|
1137 | tmp0=getMap(tmp1,"rangeClosure"); |
---|
1138 | if(tmp0!=NULL){ |
---|
1139 | const char *tmp="closed"; |
---|
1140 | if(strcasecmp(tmp0->value,"co")==0) |
---|
1141 | tmp="closed-open"; |
---|
1142 | else |
---|
1143 | if(strcasecmp(tmp0->value,"oc")==0) |
---|
1144 | tmp="open-closed"; |
---|
1145 | else |
---|
1146 | if(strcasecmp(tmp0->value,"o")==0) |
---|
1147 | tmp="open"; |
---|
1148 | xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp); |
---|
1149 | }else |
---|
1150 | xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST "closed"); |
---|
1151 | } |
---|
1152 | if(_tmp0==NULL){ |
---|
1153 | xmlAddChild(nc6,nc8); |
---|
1154 | _tmp0=e->supported; |
---|
1155 | if(_tmp0!=NULL && |
---|
1156 | (getMap(_tmp0->content,"range")!=NULL || |
---|
1157 | getMap(_tmp0->content,"rangeMin")!=NULL || |
---|
1158 | getMap(_tmp0->content,"rangeMax")!=NULL || |
---|
1159 | getMap(_tmp0->content,"rangeClosure")!=NULL )){ |
---|
1160 | tmp1=_tmp0->content; |
---|
1161 | goto doRange; |
---|
1162 | } |
---|
1163 | }else{ |
---|
1164 | _tmp0=_tmp0->next; |
---|
1165 | if(_tmp0!=NULL){ |
---|
1166 | xmlAddChild(nc6,nc8); |
---|
1167 | if(getMap(_tmp0->content,"range")!=NULL || |
---|
1168 | getMap(_tmp0->content,"rangeMin")!=NULL || |
---|
1169 | getMap(_tmp0->content,"rangeMax")!=NULL || |
---|
1170 | getMap(_tmp0->content,"rangeClosure")!=NULL ){ |
---|
1171 | tmp1=_tmp0->content; |
---|
1172 | goto doRange; |
---|
1173 | } |
---|
1174 | } |
---|
1175 | } |
---|
1176 | xmlAddChild(nc6,nc8); |
---|
1177 | if(vid==0) |
---|
1178 | xmlAddChild(nc3,nc6); |
---|
1179 | else |
---|
1180 | xmlAddChild(nc5,nc6); |
---|
1181 | isAnyValue=-1; |
---|
1182 | } |
---|
1183 | |
---|
1184 | } |
---|
1185 | |
---|
1186 | int oI=0; |
---|
1187 | /*if(vid==0)*/ { |
---|
1188 | for(oI=0;oI<13;oI++) |
---|
1189 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
1190 | #ifdef DEBUG |
---|
1191 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
1192 | #endif |
---|
1193 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
1194 | strncasecmp(tmp1->name,"DataType",8)!=0 && |
---|
1195 | strcasecmp(tmp1->name,"extension")!=0 && |
---|
1196 | strcasecmp(tmp1->name,"value")!=0 && |
---|
1197 | strcasecmp(tmp1->name,"AllowedValues")!=0 && |
---|
1198 | strncasecmp(tmp1->name,"range",5)!=0){ |
---|
1199 | if(datatype!=1){ |
---|
1200 | char *tmp2=zCapitalize1(tmp1->name); |
---|
1201 | nc9 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
1202 | free(tmp2); |
---|
1203 | } |
---|
1204 | else{ |
---|
1205 | char *tmp2=zCapitalize(tmp1->name); |
---|
1206 | nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
1207 | free(tmp2); |
---|
1208 | } |
---|
1209 | xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); |
---|
1210 | if(vid==0 || oI>=3){ |
---|
1211 | if(vid==0 || oI!=4) |
---|
1212 | xmlAddChild(nc5,nc9); |
---|
1213 | if(oI==4 && vid==1){ |
---|
1214 | xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true"); |
---|
1215 | } |
---|
1216 | } |
---|
1217 | else |
---|
1218 | xmlFree(nc9); |
---|
1219 | if(strcasecmp(tmp1->name,"uom")==0) |
---|
1220 | hasUOM1=true; |
---|
1221 | hasUOM=true; |
---|
1222 | }else |
---|
1223 | tmp1=tmp1->next; |
---|
1224 | } |
---|
1225 | } |
---|
1226 | |
---|
1227 | if(datatype!=2){ |
---|
1228 | if(hasUOM==true){ |
---|
1229 | if(vid==0){ |
---|
1230 | xmlAddChild(nc4,nc5); |
---|
1231 | xmlAddChild(nc3,nc4); |
---|
1232 | } |
---|
1233 | else{ |
---|
1234 | xmlAddChild(nc3,nc5); |
---|
1235 | } |
---|
1236 | }else{ |
---|
1237 | if(hasUOM1==false && vid==0){ |
---|
1238 | xmlFreeNode(nc5); |
---|
1239 | if(datatype==1) |
---|
1240 | xmlFreeNode(nc4); |
---|
1241 | } |
---|
1242 | else |
---|
1243 | xmlAddChild(nc3,nc5); |
---|
1244 | } |
---|
1245 | }else{ |
---|
1246 | xmlAddChild(nc3,nc5); |
---|
1247 | } |
---|
1248 | |
---|
1249 | if(datatype!=1 && default1<0){ |
---|
1250 | xmlFreeNode(nc5); |
---|
1251 | if(datatype!=2) |
---|
1252 | xmlFreeNode(nc4); |
---|
1253 | } |
---|
1254 | |
---|
1255 | |
---|
1256 | if((isInput || vid==1) && datatype==1 && |
---|
1257 | getMap(_tmp->content,"AllowedValues")==NULL && |
---|
1258 | getMap(_tmp->content,"range")==NULL && |
---|
1259 | getMap(_tmp->content,"rangeMin")==NULL && |
---|
1260 | getMap(_tmp->content,"rangeMax")==NULL && |
---|
1261 | getMap(_tmp->content,"rangeClosure")==NULL ){ |
---|
1262 | tmp1=getMap(_tmp->content,"dataType"); |
---|
1263 | // We were tempted to define default value for boolean as {true,false} |
---|
1264 | if(tmp1!=NULL && strcasecmp(tmp1->value,"boolean")==0){ |
---|
1265 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
1266 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
1267 | xmlAddChild(nc7,xmlNewText(BAD_CAST "true")); |
---|
1268 | xmlAddChild(nc6,nc7); |
---|
1269 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
1270 | xmlAddChild(nc7,xmlNewText(BAD_CAST "false")); |
---|
1271 | xmlAddChild(nc6,nc7); |
---|
1272 | if(vid==0) |
---|
1273 | xmlAddChild(nc3,nc6); |
---|
1274 | else |
---|
1275 | xmlAddChild(nc5,nc6); |
---|
1276 | } |
---|
1277 | else |
---|
1278 | if(vid==0) |
---|
1279 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
1280 | else |
---|
1281 | xmlAddChild(nc5,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
1282 | } |
---|
1283 | |
---|
1284 | if(vid==1){ |
---|
1285 | if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){ |
---|
1286 | nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
1287 | xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value)); |
---|
1288 | char tmp[1024]; |
---|
1289 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
1290 | xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
1291 | if(vid==0) |
---|
1292 | xmlAddChild(nc3,nc8); |
---|
1293 | else |
---|
1294 | xmlAddChild(nc5,nc8); |
---|
1295 | datatype=1; |
---|
1296 | } |
---|
1297 | if(hasUOM==true){ |
---|
1298 | tmp1=getMap(_tmp->content,"uom"); |
---|
1299 | if(tmp1!=NULL){ |
---|
1300 | char *tmp2=zCapitalize(tmp1->name); |
---|
1301 | nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
1302 | free(tmp2); |
---|
1303 | //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true"); |
---|
1304 | xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); |
---|
1305 | xmlAddChild(nc5,nc9); |
---|
1306 | /*struct iotype * _ltmp=e->supported; |
---|
1307 | while(_ltmp!=NULL){ |
---|
1308 | tmp1=getMap(_ltmp->content,"uom"); |
---|
1309 | if(tmp1!=NULL){ |
---|
1310 | char *tmp2=zCapitalize(tmp1->name); |
---|
1311 | nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
1312 | free(tmp2); |
---|
1313 | xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); |
---|
1314 | xmlAddChild(nc5,nc9); |
---|
1315 | } |
---|
1316 | _ltmp=_ltmp->next; |
---|
1317 | }*/ |
---|
1318 | |
---|
1319 | } |
---|
1320 | } |
---|
1321 | if(e->defaults!=NULL && (tmp1=getMap(e->defaults->content,"value"))!=NULL){ |
---|
1322 | nc7 = xmlNewNode(ns_ows, BAD_CAST "DefaultValue"); |
---|
1323 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
1324 | xmlAddChild(nc5,nc7); |
---|
1325 | } |
---|
1326 | } |
---|
1327 | |
---|
1328 | map* metadata=e->metadata; |
---|
1329 | xmlNodePtr n=NULL; |
---|
1330 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
1331 | xmlNsPtr ns_xlink=usedNs[xlinkId]; |
---|
1332 | |
---|
1333 | while(metadata!=NULL){ |
---|
1334 | nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
1335 | xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value); |
---|
1336 | xmlAddChild(nc2,nc6); |
---|
1337 | metadata=metadata->next; |
---|
1338 | } |
---|
1339 | |
---|
1340 | } |
---|
1341 | |
---|
1342 | _tmp=e->supported; |
---|
1343 | if(_tmp==NULL && datatype!=1) |
---|
1344 | _tmp=e->defaults; |
---|
1345 | |
---|
1346 | int hasSupported=-1; |
---|
1347 | |
---|
1348 | while(_tmp!=NULL){ |
---|
1349 | if(hasSupported<0){ |
---|
1350 | if(datatype==0){ |
---|
1351 | if(vid==0) |
---|
1352 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
1353 | nc5 = xmlNewNode(ns1, BAD_CAST "Format"); |
---|
1354 | if(vid==1){ |
---|
1355 | int oI=0; |
---|
1356 | for(oI=0;oI<3;oI++) |
---|
1357 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
1358 | xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value); |
---|
1359 | } |
---|
1360 | } |
---|
1361 | } |
---|
1362 | else |
---|
1363 | if(vid==0) |
---|
1364 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
1365 | hasSupported=0; |
---|
1366 | }else |
---|
1367 | if(datatype==0){ |
---|
1368 | nc5 = xmlNewNode(ns1, BAD_CAST "Format"); |
---|
1369 | if(vid==1){ |
---|
1370 | int oI=0; |
---|
1371 | for(oI=0;oI<3;oI++) |
---|
1372 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
1373 | xmlNewProp(nc5,BAD_CAST orderedFields[oI],BAD_CAST tmp1->value); |
---|
1374 | } |
---|
1375 | } |
---|
1376 | } |
---|
1377 | tmp1=_tmp->content; |
---|
1378 | int oI=0; |
---|
1379 | for(oI=0;oI<6;oI++) |
---|
1380 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
1381 | #ifdef DEBUG |
---|
1382 | printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); |
---|
1383 | #endif |
---|
1384 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
1385 | strcmp(tmp1->name,"value")!=0 && |
---|
1386 | strcmp(tmp1->name,"DataType")!=0 && |
---|
1387 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
1388 | if(datatype!=1){ |
---|
1389 | char *tmp2=zCapitalize1(tmp1->name); |
---|
1390 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
1391 | free(tmp2); |
---|
1392 | } |
---|
1393 | else{ |
---|
1394 | char *tmp2=zCapitalize(tmp1->name); |
---|
1395 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
1396 | free(tmp2); |
---|
1397 | } |
---|
1398 | if(datatype==2){ |
---|
1399 | char *tmpv,*tmps; |
---|
1400 | tmps=strtok_r(tmp1->value,",",&tmpv); |
---|
1401 | while(tmps){ |
---|
1402 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmps)); |
---|
1403 | tmps=strtok_r(NULL,",",&tmpv); |
---|
1404 | if(tmps){ |
---|
1405 | char *tmp2=zCapitalize1(tmp1->name); |
---|
1406 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
1407 | free(tmp2); |
---|
1408 | } |
---|
1409 | } |
---|
1410 | } |
---|
1411 | else{ |
---|
1412 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
1413 | } |
---|
1414 | if(vid==0 || oI>=3){ |
---|
1415 | if(vid==0 || oI!=4) |
---|
1416 | xmlAddChild(nc5,nc6); |
---|
1417 | else |
---|
1418 | xmlFree(nc6); |
---|
1419 | } |
---|
1420 | else |
---|
1421 | xmlFree(nc6); |
---|
1422 | } |
---|
1423 | tmp1=tmp1->next; |
---|
1424 | } |
---|
1425 | if(hasSupported<=0){ |
---|
1426 | if(datatype==0){ |
---|
1427 | if(vid==0){ |
---|
1428 | xmlAddChild(nc4,nc5); |
---|
1429 | xmlAddChild(nc3,nc4); |
---|
1430 | } |
---|
1431 | else{ |
---|
1432 | xmlAddChild(nc3,nc5); |
---|
1433 | } |
---|
1434 | |
---|
1435 | }else{ |
---|
1436 | if(datatype!=1) |
---|
1437 | xmlAddChild(nc3,nc5); |
---|
1438 | } |
---|
1439 | hasSupported=1; |
---|
1440 | } |
---|
1441 | else |
---|
1442 | if(datatype==0){ |
---|
1443 | if(vid==0){ |
---|
1444 | xmlAddChild(nc4,nc5); |
---|
1445 | xmlAddChild(nc3,nc4); |
---|
1446 | } |
---|
1447 | else{ |
---|
1448 | xmlAddChild(nc3,nc5); |
---|
1449 | } |
---|
1450 | } |
---|
1451 | else |
---|
1452 | if(datatype!=1) |
---|
1453 | xmlAddChild(nc3,nc5); |
---|
1454 | |
---|
1455 | _tmp=_tmp->next; |
---|
1456 | } |
---|
1457 | |
---|
1458 | if(hasSupported==0){ |
---|
1459 | if(datatype==0 && vid!=0) |
---|
1460 | xmlFreeNode(nc4); |
---|
1461 | xmlFreeNode(nc5); |
---|
1462 | } |
---|
1463 | |
---|
1464 | _tmp=e->defaults; |
---|
1465 | if(datatype==1 && hasUOM1==true){ |
---|
1466 | if(vid==0){ |
---|
1467 | xmlAddChild(nc4,nc5); |
---|
1468 | xmlAddChild(nc3,nc4); |
---|
1469 | } |
---|
1470 | else{ |
---|
1471 | xmlAddChild(nc3,nc5); |
---|
1472 | } |
---|
1473 | } |
---|
1474 | |
---|
1475 | if(vid==0 && _tmp!=NULL && (tmp1=getMap(_tmp->content,"value"))!=NULL){ |
---|
1476 | nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); |
---|
1477 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
1478 | xmlAddChild(nc3,nc7); |
---|
1479 | } |
---|
1480 | |
---|
1481 | xmlAddChild(nc2,nc3); |
---|
1482 | } |
---|
1483 | |
---|
1484 | xmlAddChild(nc1,nc2); |
---|
1485 | |
---|
1486 | e=e->next; |
---|
1487 | } |
---|
1488 | } |
---|
1489 | |
---|
1490 | /** |
---|
1491 | * Generate a wps:Execute XML document. |
---|
1492 | * |
---|
1493 | * @param m the conf maps containing the main.cfg settings |
---|
1494 | * @param request the map representing the HTTP request |
---|
1495 | * @param pid the process identifier linked to a service |
---|
1496 | * @param serv the serv structure created from the zcfg file |
---|
1497 | * @param service the service name |
---|
1498 | * @param status the status returned by the service |
---|
1499 | * @param inputs the inputs provided |
---|
1500 | * @param outputs the outputs generated by the service |
---|
1501 | */ |
---|
1502 | void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ |
---|
1503 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
1504 | xmlNodePtr nr,n,nc,nc1=NULL,nc3; |
---|
1505 | xmlDocPtr doc; |
---|
1506 | time_t time1; |
---|
1507 | time(&time1); |
---|
1508 | nr=NULL; |
---|
1509 | |
---|
1510 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
1511 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
1512 | int vid=getVersionId(version->value); |
---|
1513 | n = printWPSHeader(doc,m,"Execute",root_nodes[vid][2],(version!=NULL?version->value:"1.0.0"),2); |
---|
1514 | int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps"); |
---|
1515 | ns=usedNs[wpsId]; |
---|
1516 | int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows"); |
---|
1517 | ns_ows=usedNs[owsId]; |
---|
1518 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
1519 | ns_xlink=usedNs[xlinkId]; |
---|
1520 | bool hasStoredExecuteResponse=false; |
---|
1521 | char stored_path[1024]; |
---|
1522 | memset(stored_path,0,1024); |
---|
1523 | |
---|
1524 | if(vid==0){ |
---|
1525 | char tmp[256]; |
---|
1526 | char url[1024]; |
---|
1527 | memset(tmp,0,256); |
---|
1528 | memset(url,0,1024); |
---|
1529 | maps* tmp_maps=getMaps(m,"main"); |
---|
1530 | if(tmp_maps!=NULL){ |
---|
1531 | map* tmpm1=getMap(tmp_maps->content,"serverAddress"); |
---|
1532 | /** |
---|
1533 | * Check if the ZOO Service GetStatus is available in the local directory. |
---|
1534 | * If yes, then it uses a reference to an URL which the client can access |
---|
1535 | * to get information on the status of a running Service (using the |
---|
1536 | * percentCompleted attribute). |
---|
1537 | * Else fallback to the initial method using the xml file to write in ... |
---|
1538 | */ |
---|
1539 | char ntmp[1024]; |
---|
1540 | #ifndef WIN32 |
---|
1541 | getcwd(ntmp,1024); |
---|
1542 | #else |
---|
1543 | _getcwd(ntmp,1024); |
---|
1544 | #endif |
---|
1545 | struct stat myFileInfo; |
---|
1546 | int statRes; |
---|
1547 | char file_path[1024]; |
---|
1548 | sprintf(file_path,"%s/GetStatus.zcfg",ntmp); |
---|
1549 | statRes=stat(file_path,&myFileInfo); |
---|
1550 | if(statRes==0){ |
---|
1551 | char currentSid[128]; |
---|
1552 | map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); |
---|
1553 | map *tmp_lenv=NULL; |
---|
1554 | tmp_lenv=getMapFromMaps(m,"lenv","usid"); |
---|
1555 | if(tmp_lenv==NULL) |
---|
1556 | sprintf(currentSid,"%i",pid); |
---|
1557 | else |
---|
1558 | sprintf(currentSid,"%s",tmp_lenv->value); |
---|
1559 | if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ |
---|
1560 | sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1561 | }else{ |
---|
1562 | if(strlen(tmpm->value)>0) |
---|
1563 | if(strcasecmp(tmpm->value,"true")!=0) |
---|
1564 | sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); |
---|
1565 | else |
---|
1566 | sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); |
---|
1567 | else |
---|
1568 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1569 | } |
---|
1570 | }else{ |
---|
1571 | int lpid; |
---|
1572 | map* tmpm2=getMapFromMaps(m,"lenv","usid"); |
---|
1573 | map* tmpm3=getMap(tmp_maps->content,"tmpUrl"); |
---|
1574 | if(tmpm1!=NULL && tmpm3!=NULL){ |
---|
1575 | if( strncasecmp( tmpm3->value, "http://", 7) == 0 || |
---|
1576 | strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){ |
---|
1577 | sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value); |
---|
1578 | }else |
---|
1579 | sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value); |
---|
1580 | } |
---|
1581 | } |
---|
1582 | if(tmpm1!=NULL){ |
---|
1583 | sprintf(tmp,"%s",tmpm1->value); |
---|
1584 | } |
---|
1585 | int lpid; |
---|
1586 | map* tmpm2=getMapFromMaps(m,"lenv","usid"); |
---|
1587 | tmpm1=getMapFromMaps(m,"main","TmpPath"); |
---|
1588 | sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value); |
---|
1589 | } |
---|
1590 | |
---|
1591 | xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); |
---|
1592 | map* test=getMap(request,"storeExecuteResponse"); |
---|
1593 | if(test!=NULL && strcasecmp(test->value,"true")==0){ |
---|
1594 | xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); |
---|
1595 | hasStoredExecuteResponse=true; |
---|
1596 | } |
---|
1597 | |
---|
1598 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
1599 | map* tmp2=getMap(serv->content,"processVersion"); |
---|
1600 | if(tmp2!=NULL) |
---|
1601 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); |
---|
1602 | |
---|
1603 | map* tmpI=getMapFromMaps(m,"lenv","oIdentifier"); |
---|
1604 | printDescription(nc,ns_ows,tmpI->value,serv->content,0); |
---|
1605 | |
---|
1606 | xmlAddChild(n,nc); |
---|
1607 | |
---|
1608 | nc = xmlNewNode(ns, BAD_CAST "Status"); |
---|
1609 | const struct tm *tm; |
---|
1610 | size_t len; |
---|
1611 | time_t now; |
---|
1612 | char *tmp1; |
---|
1613 | map *tmpStatus; |
---|
1614 | |
---|
1615 | now = time ( NULL ); |
---|
1616 | tm = localtime ( &now ); |
---|
1617 | |
---|
1618 | tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); |
---|
1619 | |
---|
1620 | len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); |
---|
1621 | |
---|
1622 | xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); |
---|
1623 | |
---|
1624 | char sMsg[2048]; |
---|
1625 | switch(status){ |
---|
1626 | case SERVICE_SUCCEEDED: |
---|
1627 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); |
---|
1628 | sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name); |
---|
1629 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1630 | xmlAddChild(nc1,nc3); |
---|
1631 | break; |
---|
1632 | case SERVICE_STARTED: |
---|
1633 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); |
---|
1634 | tmpStatus=getMapFromMaps(m,"lenv","status"); |
---|
1635 | xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); |
---|
1636 | sprintf(sMsg,_("The ZOO service \"%s\" is currently running. Please reload this document to get the up-to-date status of the service."),serv->name); |
---|
1637 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1638 | xmlAddChild(nc1,nc3); |
---|
1639 | break; |
---|
1640 | case SERVICE_ACCEPTED: |
---|
1641 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); |
---|
1642 | sprintf(sMsg,_("The service \"%s\" was accepted by the ZOO kernel and is running as a background task. Please access the URL in the statusLocation attribute provided in this document to get the up-to-date status and results."),serv->name); |
---|
1643 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1644 | xmlAddChild(nc1,nc3); |
---|
1645 | break; |
---|
1646 | case SERVICE_FAILED: |
---|
1647 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); |
---|
1648 | map *errorMap; |
---|
1649 | map *te; |
---|
1650 | te=getMapFromMaps(m,"lenv","code"); |
---|
1651 | if(te!=NULL) |
---|
1652 | errorMap=createMap("code",te->value); |
---|
1653 | else |
---|
1654 | errorMap=createMap("code","NoApplicableCode"); |
---|
1655 | te=getMapFromMaps(m,"lenv","message"); |
---|
1656 | if(te!=NULL) |
---|
1657 | addToMap(errorMap,"text",_ss(te->value)); |
---|
1658 | else |
---|
1659 | addToMap(errorMap,"text",_("No more information available")); |
---|
1660 | nc3=createExceptionReportNode(m,errorMap,0); |
---|
1661 | freeMap(&errorMap); |
---|
1662 | free(errorMap); |
---|
1663 | xmlAddChild(nc1,nc3); |
---|
1664 | break; |
---|
1665 | default : |
---|
1666 | printf(_("error code not know : %i\n"),status); |
---|
1667 | //exit(1); |
---|
1668 | break; |
---|
1669 | } |
---|
1670 | xmlAddChild(nc,nc1); |
---|
1671 | xmlAddChild(n,nc); |
---|
1672 | free(tmp1); |
---|
1673 | |
---|
1674 | #ifdef DEBUG |
---|
1675 | fprintf(stderr,"printProcessResponse %d\n",__LINE__); |
---|
1676 | #endif |
---|
1677 | |
---|
1678 | map* lineage=getMap(request,"lineage"); |
---|
1679 | if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){ |
---|
1680 | nc = xmlNewNode(ns, BAD_CAST "DataInputs"); |
---|
1681 | maps* mcursor=inputs; |
---|
1682 | elements* scursor=NULL; |
---|
1683 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
1684 | scursor=getElements(serv->inputs,mcursor->name); |
---|
1685 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input",vid); |
---|
1686 | mcursor=mcursor->next; |
---|
1687 | } |
---|
1688 | xmlAddChild(n,nc); |
---|
1689 | |
---|
1690 | nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); |
---|
1691 | mcursor=outputs; |
---|
1692 | scursor=NULL; |
---|
1693 | while(mcursor!=NULL){ |
---|
1694 | scursor=getElements(serv->outputs,mcursor->name); |
---|
1695 | printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
1696 | mcursor=mcursor->next; |
---|
1697 | } |
---|
1698 | xmlAddChild(n,nc); |
---|
1699 | } |
---|
1700 | } |
---|
1701 | |
---|
1702 | /** |
---|
1703 | * Display the process output only when requested ! |
---|
1704 | */ |
---|
1705 | if(status==SERVICE_SUCCEEDED){ |
---|
1706 | if(vid==0){ |
---|
1707 | nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); |
---|
1708 | } |
---|
1709 | maps* mcursor=outputs; |
---|
1710 | elements* scursor=serv->outputs; |
---|
1711 | map* testResponse=getMap(request,"RawDataOutput"); |
---|
1712 | if(testResponse==NULL) |
---|
1713 | testResponse=getMap(request,"ResponseDocument"); |
---|
1714 | while(mcursor!=NULL){ |
---|
1715 | map* tmp0=getMap(mcursor->content,"inRequest"); |
---|
1716 | scursor=getElements(serv->outputs,mcursor->name); |
---|
1717 | if(scursor!=NULL){ |
---|
1718 | if(testResponse==NULL || tmp0==NULL){ |
---|
1719 | if(vid==0) |
---|
1720 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1721 | else |
---|
1722 | printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1723 | } |
---|
1724 | else |
---|
1725 | |
---|
1726 | if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){ |
---|
1727 | if(vid==0) |
---|
1728 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1729 | else |
---|
1730 | printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1731 | } |
---|
1732 | }else |
---|
1733 | /** |
---|
1734 | * In case there was no definition found in the ZCFG file but |
---|
1735 | * present in the service code |
---|
1736 | */ |
---|
1737 | if(vid==0) |
---|
1738 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1739 | else |
---|
1740 | printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); |
---|
1741 | mcursor=mcursor->next; |
---|
1742 | } |
---|
1743 | if(vid==0) |
---|
1744 | xmlAddChild(n,nc); |
---|
1745 | } |
---|
1746 | |
---|
1747 | if(vid==0 && hasStoredExecuteResponse==true && status!=SERVICE_STARTED && status!=SERVICE_ACCEPTED){ |
---|
1748 | #ifndef RELY_ON_DB |
---|
1749 | semid lid=acquireLock(m);//,1); |
---|
1750 | if(lid<0){ |
---|
1751 | /* If the lock failed */ |
---|
1752 | errorException(m,_("Lock failed."),"InternalError",NULL); |
---|
1753 | xmlFreeDoc(doc); |
---|
1754 | xmlCleanupParser(); |
---|
1755 | zooXmlCleanupNs(); |
---|
1756 | return; |
---|
1757 | } |
---|
1758 | else{ |
---|
1759 | #endif |
---|
1760 | /* We need to write the ExecuteResponse Document somewhere */ |
---|
1761 | FILE* output=fopen(stored_path,"w"); |
---|
1762 | if(output==NULL){ |
---|
1763 | /* If the file cannot be created return an ExceptionReport */ |
---|
1764 | char tmpMsg[1024]; |
---|
1765 | sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path); |
---|
1766 | |
---|
1767 | errorException(m,tmpMsg,"InternalError",NULL); |
---|
1768 | xmlFreeDoc(doc); |
---|
1769 | xmlCleanupParser(); |
---|
1770 | zooXmlCleanupNs(); |
---|
1771 | #ifndef RELY_ON_DB |
---|
1772 | unlockShm(lid); |
---|
1773 | #endif |
---|
1774 | return; |
---|
1775 | } |
---|
1776 | xmlChar *xmlbuff; |
---|
1777 | int buffersize; |
---|
1778 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); |
---|
1779 | fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output); |
---|
1780 | xmlFree(xmlbuff); |
---|
1781 | fclose(output); |
---|
1782 | #ifndef RELY_ON_DB |
---|
1783 | #ifdef DEBUG |
---|
1784 | fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__); |
---|
1785 | #endif |
---|
1786 | unlockShm(lid); |
---|
1787 | map* v=getMapFromMaps(m,"lenv","sid"); |
---|
1788 | // Remove the lock when running as a normal task |
---|
1789 | if(getpid()==atoi(v->value)){ |
---|
1790 | removeShmLock (m, 1); |
---|
1791 | } |
---|
1792 | } |
---|
1793 | #endif |
---|
1794 | } |
---|
1795 | printDocument(m,doc,pid); |
---|
1796 | |
---|
1797 | xmlCleanupParser(); |
---|
1798 | zooXmlCleanupNs(); |
---|
1799 | } |
---|
1800 | |
---|
1801 | /** |
---|
1802 | * Print a XML document. |
---|
1803 | * |
---|
1804 | * @param m the conf maps containing the main.cfg settings |
---|
1805 | * @param doc the XML document |
---|
1806 | * @param pid the process identifier linked to a service |
---|
1807 | */ |
---|
1808 | void printDocument(maps* m, xmlDocPtr doc,int pid){ |
---|
1809 | char *encoding=getEncoding(m); |
---|
1810 | if(pid==getpid()){ |
---|
1811 | printHeaders(m); |
---|
1812 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1813 | } |
---|
1814 | fflush(stdout); |
---|
1815 | xmlChar *xmlbuff; |
---|
1816 | int buffersize; |
---|
1817 | /* |
---|
1818 | * Dump the document to a buffer and print it on stdout |
---|
1819 | * for demonstration purposes. |
---|
1820 | */ |
---|
1821 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
1822 | printf("%s",xmlbuff); |
---|
1823 | fflush(stdout); |
---|
1824 | /* |
---|
1825 | * Free associated memory. |
---|
1826 | */ |
---|
1827 | xmlFree(xmlbuff); |
---|
1828 | xmlFreeDoc(doc); |
---|
1829 | xmlCleanupParser(); |
---|
1830 | zooXmlCleanupNs(); |
---|
1831 | } |
---|
1832 | |
---|
1833 | /** |
---|
1834 | * Print a XML document. |
---|
1835 | * |
---|
1836 | * @param doc the XML document (unused) |
---|
1837 | * @param nc the XML node to add the output definition |
---|
1838 | * @param ns_wps the wps XML namespace |
---|
1839 | * @param ns_ows the ows XML namespace |
---|
1840 | * @param e the output elements |
---|
1841 | * @param m the conf maps containing the main.cfg settings |
---|
1842 | * @param type the type (unused) |
---|
1843 | */ |
---|
1844 | void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){ |
---|
1845 | xmlNodePtr nc1; |
---|
1846 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1847 | map *tmp=NULL; |
---|
1848 | if(e!=NULL && e->defaults!=NULL) |
---|
1849 | tmp=e->defaults->content; |
---|
1850 | else{ |
---|
1851 | /* |
---|
1852 | dumpElements(e); |
---|
1853 | */ |
---|
1854 | return; |
---|
1855 | } |
---|
1856 | while(tmp!=NULL){ |
---|
1857 | if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 |
---|
1858 | || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 |
---|
1859 | || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 |
---|
1860 | || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) |
---|
1861 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1862 | tmp=tmp->next; |
---|
1863 | } |
---|
1864 | tmp=getMap(e->defaults->content,"asReference"); |
---|
1865 | if(tmp==NULL) |
---|
1866 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
1867 | |
---|
1868 | tmp=e->content; |
---|
1869 | |
---|
1870 | printDescription(nc1,ns_ows,m->name,e->content,0); |
---|
1871 | |
---|
1872 | xmlAddChild(nc,nc1); |
---|
1873 | |
---|
1874 | } |
---|
1875 | |
---|
1876 | /** |
---|
1877 | * Generate XML nodes describing inputs or outputs metadata. |
---|
1878 | * |
---|
1879 | * @param doc the XML document |
---|
1880 | * @param nc the XML node to add the definition |
---|
1881 | * @param ns_wps the wps namespace |
---|
1882 | * @param ns_ows the ows namespace |
---|
1883 | * @param ns_xlink the xlink namespace |
---|
1884 | * @param e the output elements |
---|
1885 | * @param m the conf maps containing the main.cfg settings |
---|
1886 | * @param type the type |
---|
1887 | */ |
---|
1888 | void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){ |
---|
1889 | |
---|
1890 | xmlNodePtr nc1,nc2,nc3; |
---|
1891 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1892 | map *tmp=NULL; |
---|
1893 | if(e!=NULL) |
---|
1894 | tmp=e->content; |
---|
1895 | else |
---|
1896 | tmp=m->content; |
---|
1897 | |
---|
1898 | if(vid==0){ |
---|
1899 | nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
1900 | if(e!=NULL) |
---|
1901 | nc3=xmlNewText(BAD_CAST e->name); |
---|
1902 | else |
---|
1903 | nc3=xmlNewText(BAD_CAST m->name); |
---|
1904 | |
---|
1905 | xmlAddChild(nc2,nc3); |
---|
1906 | xmlAddChild(nc1,nc2); |
---|
1907 | |
---|
1908 | xmlAddChild(nc,nc1); |
---|
1909 | |
---|
1910 | if(e!=NULL) |
---|
1911 | tmp=getMap(e->content,"Title"); |
---|
1912 | else |
---|
1913 | tmp=getMap(m->content,"Title"); |
---|
1914 | |
---|
1915 | if(tmp!=NULL){ |
---|
1916 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1917 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1918 | xmlAddChild(nc2,nc3); |
---|
1919 | xmlAddChild(nc1,nc2); |
---|
1920 | } |
---|
1921 | |
---|
1922 | if(e!=NULL) |
---|
1923 | tmp=getMap(e->content,"Abstract"); |
---|
1924 | else |
---|
1925 | tmp=getMap(m->content,"Abstract"); |
---|
1926 | |
---|
1927 | if(tmp!=NULL){ |
---|
1928 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1929 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1930 | xmlAddChild(nc2,nc3); |
---|
1931 | xmlAddChild(nc1,nc2); |
---|
1932 | xmlAddChild(nc,nc1); |
---|
1933 | } |
---|
1934 | }else{ |
---|
1935 | xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name)); |
---|
1936 | } |
---|
1937 | |
---|
1938 | /** |
---|
1939 | * IO type Reference or full Data ? |
---|
1940 | */ |
---|
1941 | map *tmpMap=getMap(m->content,"Reference"); |
---|
1942 | if(tmpMap==NULL){ |
---|
1943 | nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); |
---|
1944 | if(e!=NULL){ |
---|
1945 | if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0) |
---|
1946 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
1947 | else |
---|
1948 | if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) |
---|
1949 | nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); |
---|
1950 | else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0) |
---|
1951 | nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); |
---|
1952 | else |
---|
1953 | nc3=xmlNewNode(ns_wps, BAD_CAST e->format); |
---|
1954 | } |
---|
1955 | else { |
---|
1956 | map* tmpV=getMapFromMaps(m,"format","value"); |
---|
1957 | if(tmpV!=NULL) |
---|
1958 | nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); |
---|
1959 | else |
---|
1960 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
1961 | } |
---|
1962 | tmp=m->content; |
---|
1963 | |
---|
1964 | while(tmp!=NULL){ |
---|
1965 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
1966 | strcasecmp(tmp->name,"encoding")==0 || |
---|
1967 | strcasecmp(tmp->name,"schema")==0 || |
---|
1968 | strcasecmp(tmp->name,"datatype")==0 || |
---|
1969 | strcasecmp(tmp->name,"uom")==0) { |
---|
1970 | |
---|
1971 | if(vid==0) |
---|
1972 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1973 | else{ |
---|
1974 | if(strcasecmp(tmp->name,"datatype")==0) |
---|
1975 | xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain"); |
---|
1976 | else |
---|
1977 | if(strcasecmp(tmp->name,"uom")!=0) |
---|
1978 | xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1979 | } |
---|
1980 | } |
---|
1981 | if(vid==0) |
---|
1982 | xmlAddChild(nc2,nc3); |
---|
1983 | tmp=tmp->next; |
---|
1984 | } |
---|
1985 | if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) { |
---|
1986 | map* bb=getMap(m->content,"value"); |
---|
1987 | if(bb!=NULL) { |
---|
1988 | map* tmpRes=parseBoundingBox(bb->value); |
---|
1989 | printBoundingBox(ns_ows,nc3,tmpRes); |
---|
1990 | freeMap(&tmpRes); |
---|
1991 | free(tmpRes); |
---|
1992 | } |
---|
1993 | } |
---|
1994 | else { |
---|
1995 | if(e!=NULL) |
---|
1996 | tmp=getMap(e->defaults->content,"mimeType"); |
---|
1997 | else |
---|
1998 | tmp=NULL; |
---|
1999 | |
---|
2000 | map* tmp1=getMap(m->content,"encoding"); |
---|
2001 | map* tmp2=getMap(m->content,"mimeType"); |
---|
2002 | map* tmp3=getMap(m->content,"value"); |
---|
2003 | int hasValue=1; |
---|
2004 | if(tmp3==NULL){ |
---|
2005 | tmp3=createMap("value",""); |
---|
2006 | hasValue=-1; |
---|
2007 | } |
---|
2008 | |
---|
2009 | if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 ) // if encoding is base64 |
---|
2010 | || // or if |
---|
2011 | ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL // mime type is not text |
---|
2012 | && // nor |
---|
2013 | strstr(tmp2->value,"xml") == NULL // xml |
---|
2014 | && // nor |
---|
2015 | strstr(tmp2->value,"javascript") == NULL // javascript |
---|
2016 | && |
---|
2017 | strstr(tmp2->value,"json") == NULL |
---|
2018 | && |
---|
2019 | strstr(tmp2->value,"ecmascript") == NULL |
---|
2020 | && |
---|
2021 | // include for backwards compatibility, |
---|
2022 | // although correct mime type is ...kml+xml: |
---|
2023 | strstr(tmp2->value,"google-earth.kml") == NULL ) |
---|
2024 | ) |
---|
2025 | ) { // then |
---|
2026 | map* rs=getMap(m->content,"size"); // obtain size |
---|
2027 | bool isSized=true; |
---|
2028 | if(rs==NULL){ |
---|
2029 | char tmp1[1024]; |
---|
2030 | sprintf(tmp1,"%ld",strlen(tmp3->value)); |
---|
2031 | rs=createMap("size",tmp1); |
---|
2032 | isSized=false; |
---|
2033 | } |
---|
2034 | |
---|
2035 | xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value)))); // base 64 encode in XML |
---|
2036 | |
---|
2037 | if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) { |
---|
2038 | xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding"); |
---|
2039 | if (ap != NULL) { |
---|
2040 | xmlRemoveProp(ap); |
---|
2041 | } |
---|
2042 | xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64"); |
---|
2043 | } |
---|
2044 | |
---|
2045 | if(!isSized){ |
---|
2046 | freeMap(&rs); |
---|
2047 | free(rs); |
---|
2048 | } |
---|
2049 | } |
---|
2050 | else if (tmp2!=NULL) { // else (text-based format) |
---|
2051 | if(strstr(tmp2->value, "javascript") != NULL || // if javascript put code in CDATA block |
---|
2052 | strstr(tmp2->value, "json") != NULL || // (will not be parsed by XML reader) |
---|
2053 | strstr(tmp2->value, "ecmascript") != NULL |
---|
2054 | ) { |
---|
2055 | xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); |
---|
2056 | } |
---|
2057 | else { // else |
---|
2058 | if (strstr(tmp2->value, "xml") != NULL || // if XML-based format |
---|
2059 | // include for backwards compatibility, |
---|
2060 | // although correct mime type is ...kml+xml: |
---|
2061 | strstr(tmp2->value, "google-earth.kml") != NULL |
---|
2062 | ) { |
---|
2063 | |
---|
2064 | int li=zooXmlAddDoc(tmp3->value); |
---|
2065 | xmlDocPtr doc = iDocs[li]; |
---|
2066 | xmlNodePtr ir = xmlDocGetRootElement(doc); |
---|
2067 | xmlAddChild((vid==0?nc3:nc2),ir); |
---|
2068 | } |
---|
2069 | else // else |
---|
2070 | xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value)); // add text node |
---|
2071 | } |
---|
2072 | xmlAddChild(nc2,nc3); |
---|
2073 | } |
---|
2074 | else { |
---|
2075 | xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value)); |
---|
2076 | } |
---|
2077 | |
---|
2078 | if(hasValue<0) { |
---|
2079 | freeMap(&tmp3); |
---|
2080 | free(tmp3); |
---|
2081 | } |
---|
2082 | } |
---|
2083 | } |
---|
2084 | else { // Reference |
---|
2085 | tmpMap=getMap(m->content,"Reference"); |
---|
2086 | nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); |
---|
2087 | if(strcasecmp(type,"Output")==0) |
---|
2088 | xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
2089 | else |
---|
2090 | xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
2091 | |
---|
2092 | tmp=m->content; |
---|
2093 | while(tmp!=NULL) { |
---|
2094 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
2095 | strcasecmp(tmp->name,"encoding")==0 || |
---|
2096 | strcasecmp(tmp->name,"schema")==0 || |
---|
2097 | strcasecmp(tmp->name,"datatype")==0 || |
---|
2098 | strcasecmp(tmp->name,"uom")==0){ |
---|
2099 | |
---|
2100 | if(strcasecmp(tmp->name,"datatype")==0) |
---|
2101 | xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain"); |
---|
2102 | else |
---|
2103 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
2104 | } |
---|
2105 | tmp=tmp->next; |
---|
2106 | xmlAddChild(nc2,nc3); |
---|
2107 | } |
---|
2108 | } |
---|
2109 | xmlAddChild(nc1,nc2); |
---|
2110 | xmlAddChild(nc,nc1); |
---|
2111 | } |
---|
2112 | |
---|
2113 | /** |
---|
2114 | * Create XML node with basic ows metadata informations (Identifier,Title,Abstract) |
---|
2115 | * |
---|
2116 | * @param root the root XML node to add the description |
---|
2117 | * @param ns_ows the ows XML namespace |
---|
2118 | * @param identifier the identifier to use |
---|
2119 | * @param amap the map containing the ows metadata informations |
---|
2120 | */ |
---|
2121 | void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap,int vid=0){ |
---|
2122 | xmlNodePtr nc2; |
---|
2123 | if(vid==0){ |
---|
2124 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
2125 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
2126 | xmlAddChild(root,nc2); |
---|
2127 | } |
---|
2128 | map* tmp=amap; |
---|
2129 | const char *tmp2[2]; |
---|
2130 | tmp2[0]="Title"; |
---|
2131 | tmp2[1]="Abstract"; |
---|
2132 | int j=0; |
---|
2133 | for(j=0;j<2;j++){ |
---|
2134 | map* tmp1=getMap(tmp,tmp2[j]); |
---|
2135 | if(tmp1!=NULL){ |
---|
2136 | nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); |
---|
2137 | xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); |
---|
2138 | xmlAddChild(root,nc2); |
---|
2139 | } |
---|
2140 | } |
---|
2141 | if(vid==1){ |
---|
2142 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
2143 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
2144 | xmlAddChild(root,nc2); |
---|
2145 | } |
---|
2146 | } |
---|
2147 | |
---|
2148 | /** |
---|
2149 | * Print an OWS ExceptionReport Document and HTTP headers (when required) |
---|
2150 | * depending on the code. |
---|
2151 | * Set hasPrinted value to true in the [lenv] section. |
---|
2152 | * |
---|
2153 | * @param m the maps containing the settings of the main.cfg file |
---|
2154 | * @param s the map containing the text,code,locator keys |
---|
2155 | */ |
---|
2156 | void printExceptionReportResponse(maps* m,map* s){ |
---|
2157 | if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) |
---|
2158 | return; |
---|
2159 | int buffersize; |
---|
2160 | xmlDocPtr doc; |
---|
2161 | xmlChar *xmlbuff; |
---|
2162 | xmlNodePtr n; |
---|
2163 | |
---|
2164 | zooXmlCleanupNs(); |
---|
2165 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
2166 | maps* tmpMap=getMaps(m,"main"); |
---|
2167 | char *encoding=getEncoding(tmpMap); |
---|
2168 | const char *exceptionCode; |
---|
2169 | |
---|
2170 | map* tmp=getMap(s,"code"); |
---|
2171 | if(tmp!=NULL){ |
---|
2172 | if(strcmp(tmp->value,"OperationNotSupported")==0 || |
---|
2173 | strcmp(tmp->value,"NoApplicableCode")==0) |
---|
2174 | exceptionCode="501 Not Implemented"; |
---|
2175 | else |
---|
2176 | if(strcmp(tmp->value,"MissingParameterValue")==0 || |
---|
2177 | strcmp(tmp->value,"InvalidUpdateSequence")==0 || |
---|
2178 | strcmp(tmp->value,"OptionNotSupported")==0 || |
---|
2179 | strcmp(tmp->value,"VersionNegotiationFailed")==0 || |
---|
2180 | strcmp(tmp->value,"InvalidParameterValue")==0) |
---|
2181 | exceptionCode="400 Bad request"; |
---|
2182 | else |
---|
2183 | exceptionCode="501 Internal Server Error"; |
---|
2184 | } |
---|
2185 | else |
---|
2186 | exceptionCode="501 Internal Server Error"; |
---|
2187 | |
---|
2188 | if(m!=NULL){ |
---|
2189 | map *tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
2190 | if(tmpSid!=NULL){ |
---|
2191 | if( getpid()==atoi(tmpSid->value) ){ |
---|
2192 | printHeaders(m); |
---|
2193 | printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); |
---|
2194 | } |
---|
2195 | } |
---|
2196 | else{ |
---|
2197 | printHeaders(m); |
---|
2198 | printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); |
---|
2199 | } |
---|
2200 | }else{ |
---|
2201 | printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); |
---|
2202 | } |
---|
2203 | n=createExceptionReportNode(m,s,1); |
---|
2204 | xmlDocSetRootElement(doc, n); |
---|
2205 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
2206 | printf("%s",xmlbuff); |
---|
2207 | fflush(stdout); |
---|
2208 | xmlFreeDoc(doc); |
---|
2209 | xmlFree(xmlbuff); |
---|
2210 | xmlCleanupParser(); |
---|
2211 | zooXmlCleanupNs(); |
---|
2212 | if(m!=NULL) |
---|
2213 | setMapInMaps(m,"lenv","hasPrinted","true"); |
---|
2214 | } |
---|
2215 | |
---|
2216 | /** |
---|
2217 | * Create an OWS ExceptionReport Node. |
---|
2218 | * |
---|
2219 | * @param m the conf maps |
---|
2220 | * @param s the map containing the text,code,locator keys |
---|
2221 | * @param use_ns (0/1) choose if you want to generate an ExceptionReport or |
---|
2222 | * ows:ExceptionReport node respectively |
---|
2223 | * @return the ExceptionReport/ows:ExceptionReport node |
---|
2224 | */ |
---|
2225 | xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ |
---|
2226 | |
---|
2227 | xmlNsPtr ns,ns_xsi; |
---|
2228 | xmlNodePtr n,nc,nc1; |
---|
2229 | |
---|
2230 | int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows"); |
---|
2231 | ns=usedNs[nsid]; |
---|
2232 | if(use_ns==0){ |
---|
2233 | ns=NULL; |
---|
2234 | } |
---|
2235 | n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); |
---|
2236 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
2237 | int vid=getVersionId(version->value); |
---|
2238 | if(vid<0) |
---|
2239 | vid=0; |
---|
2240 | if(use_ns==1){ |
---|
2241 | xmlNewNs(n,BAD_CAST schemas[vid][1],BAD_CAST"ows"); |
---|
2242 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
2243 | ns_xsi=usedNs[xsiId]; |
---|
2244 | char tmp[1024]; |
---|
2245 | sprintf(tmp,"%s %s",schemas[vid][1],schemas[vid][5]); |
---|
2246 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp); |
---|
2247 | } |
---|
2248 | |
---|
2249 | |
---|
2250 | addLangAttr(n,m); |
---|
2251 | xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][6]); |
---|
2252 | |
---|
2253 | int length=1; |
---|
2254 | int cnt=0; |
---|
2255 | map* len=getMap(s,"length"); |
---|
2256 | if(len!=NULL) |
---|
2257 | length=atoi(len->value); |
---|
2258 | for(cnt=0;cnt<length;cnt++){ |
---|
2259 | nc = xmlNewNode(ns, BAD_CAST "Exception"); |
---|
2260 | |
---|
2261 | map* tmp=getMapArray(s,"code",cnt); |
---|
2262 | if(tmp==NULL) |
---|
2263 | tmp=getMap(s,"code"); |
---|
2264 | if(tmp!=NULL) |
---|
2265 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); |
---|
2266 | else |
---|
2267 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); |
---|
2268 | |
---|
2269 | tmp=getMapArray(s,"locator",cnt); |
---|
2270 | if(tmp==NULL) |
---|
2271 | tmp=getMap(s,"locator"); |
---|
2272 | if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0) |
---|
2273 | xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value); |
---|
2274 | |
---|
2275 | tmp=getMapArray(s,"text",cnt); |
---|
2276 | nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); |
---|
2277 | if(tmp!=NULL){ |
---|
2278 | xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); |
---|
2279 | xmlAddChild(nc1,txt); |
---|
2280 | } |
---|
2281 | else{ |
---|
2282 | xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); |
---|
2283 | } |
---|
2284 | xmlAddChild(nc,nc1); |
---|
2285 | xmlAddChild(n,nc); |
---|
2286 | } |
---|
2287 | return n; |
---|
2288 | } |
---|
2289 | |
---|
2290 | /** |
---|
2291 | * Print an OWS ExceptionReport. |
---|
2292 | * |
---|
2293 | * @param m the conf maps |
---|
2294 | * @param message the error message |
---|
2295 | * @param errorcode the error code |
---|
2296 | * @param locator the potential locator |
---|
2297 | */ |
---|
2298 | int errorException(maps *m, const char *message, const char *errorcode, const char *locator) |
---|
2299 | { |
---|
2300 | map* errormap = createMap("text", message); |
---|
2301 | addToMap(errormap,"code", errorcode); |
---|
2302 | if(locator!=NULL) |
---|
2303 | addToMap(errormap,"locator", locator); |
---|
2304 | else |
---|
2305 | addToMap(errormap,"locator", "NULL"); |
---|
2306 | printExceptionReportResponse(m,errormap); |
---|
2307 | freeMap(&errormap); |
---|
2308 | free(errormap); |
---|
2309 | return -1; |
---|
2310 | } |
---|
2311 | |
---|
2312 | /** |
---|
2313 | * Generate the output response (RawDataOutput or ResponseDocument) |
---|
2314 | * |
---|
2315 | * @param s the service structure containing the metadata informations |
---|
2316 | * @param request_inputs the inputs provided to the service for execution |
---|
2317 | * @param request_outputs the outputs updated by the service execution |
---|
2318 | * @param request_inputs1 the map containing the HTTP request |
---|
2319 | * @param cpid the process identifier attached to a service execution |
---|
2320 | * @param m the conf maps containing the main.cfg settings |
---|
2321 | * @param res the value returned by the service execution |
---|
2322 | */ |
---|
2323 | void outputResponse(service* s,maps* request_inputs,maps* request_outputs, |
---|
2324 | map* request_inputs1,int cpid,maps* m,int res){ |
---|
2325 | #ifdef DEBUG |
---|
2326 | dumpMaps(request_inputs); |
---|
2327 | dumpMaps(request_outputs); |
---|
2328 | fprintf(stderr,"printProcessResponse\n"); |
---|
2329 | #endif |
---|
2330 | map* toto=getMap(request_inputs1,"RawDataOutput"); |
---|
2331 | int asRaw=0; |
---|
2332 | if(toto!=NULL) |
---|
2333 | asRaw=1; |
---|
2334 | map* version=getMapFromMaps(m,"main","rversion"); |
---|
2335 | int vid=getVersionId(version->value); |
---|
2336 | |
---|
2337 | maps* tmpSess=getMaps(m,"senv"); |
---|
2338 | if(tmpSess!=NULL){ |
---|
2339 | map *_tmp=getMapFromMaps(m,"lenv","cookie"); |
---|
2340 | char* sessId=NULL; |
---|
2341 | if(_tmp!=NULL){ |
---|
2342 | printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value); |
---|
2343 | printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); |
---|
2344 | char session_file_path[100]; |
---|
2345 | char *tmp1=strtok(_tmp->value,";"); |
---|
2346 | if(tmp1!=NULL) |
---|
2347 | sprintf(session_file_path,"%s",strstr(tmp1,"=")+1); |
---|
2348 | else |
---|
2349 | sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1); |
---|
2350 | sessId=strdup(session_file_path); |
---|
2351 | }else{ |
---|
2352 | maps* t=getMaps(m,"senv"); |
---|
2353 | map*p=t->content; |
---|
2354 | while(p!=NULL){ |
---|
2355 | if(strstr(p->name,"ID")!=NULL){ |
---|
2356 | sessId=strdup(p->value); |
---|
2357 | break; |
---|
2358 | } |
---|
2359 | p=p->next; |
---|
2360 | } |
---|
2361 | } |
---|
2362 | char session_file_path[1024]; |
---|
2363 | map *tmpPath=getMapFromMaps(m,"main","sessPath"); |
---|
2364 | if(tmpPath==NULL) |
---|
2365 | tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
2366 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId); |
---|
2367 | FILE* teste=fopen(session_file_path,"w"); |
---|
2368 | if(teste==NULL){ |
---|
2369 | char tmpMsg[1024]; |
---|
2370 | sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path); |
---|
2371 | errorException(m,tmpMsg,"InternalError",NULL); |
---|
2372 | |
---|
2373 | return; |
---|
2374 | } |
---|
2375 | else{ |
---|
2376 | fclose(teste); |
---|
2377 | dumpMapsToFile(tmpSess,session_file_path); |
---|
2378 | } |
---|
2379 | } |
---|
2380 | |
---|
2381 | if(res==SERVICE_FAILED){ |
---|
2382 | map *lenv; |
---|
2383 | lenv=getMapFromMaps(m,"lenv","message"); |
---|
2384 | char *tmp0; |
---|
2385 | if(lenv!=NULL){ |
---|
2386 | tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); |
---|
2387 | sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); |
---|
2388 | } |
---|
2389 | else{ |
---|
2390 | tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); |
---|
2391 | sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service.")); |
---|
2392 | } |
---|
2393 | errorException(m,tmp0,"InternalError",NULL); |
---|
2394 | free(tmp0); |
---|
2395 | return; |
---|
2396 | } |
---|
2397 | |
---|
2398 | if(res==SERVICE_ACCEPTED && vid==1){ |
---|
2399 | map* statusInfo=createMap("Status","Accepted"); |
---|
2400 | map *usid=getMapFromMaps(m,"lenv","usid"); |
---|
2401 | addToMap(statusInfo,"JobID",usid->value); |
---|
2402 | printStatusInfo(m,statusInfo,"Execute"); |
---|
2403 | freeMap(&statusInfo); |
---|
2404 | free(statusInfo); |
---|
2405 | return; |
---|
2406 | } |
---|
2407 | |
---|
2408 | map *tmp1=getMapFromMaps(m,"main","tmpPath"); |
---|
2409 | if(asRaw==0){ |
---|
2410 | #ifdef DEBUG |
---|
2411 | fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); |
---|
2412 | dumpMaps(request_outputs); |
---|
2413 | #endif |
---|
2414 | maps* tmpI=request_outputs; |
---|
2415 | map* usid=getMapFromMaps(m,"lenv","usid"); |
---|
2416 | int itn=0; |
---|
2417 | while(tmpI!=NULL){ |
---|
2418 | #ifdef USE_MS |
---|
2419 | map* testMap=getMap(tmpI->content,"useMapserver"); |
---|
2420 | #endif |
---|
2421 | map *gfile=getMap(tmpI->content,"generated_file"); |
---|
2422 | char *file_name; |
---|
2423 | if(gfile!=NULL){ |
---|
2424 | gfile=getMap(tmpI->content,"expected_generated_file"); |
---|
2425 | if(gfile==NULL){ |
---|
2426 | gfile=getMap(tmpI->content,"generated_file"); |
---|
2427 | } |
---|
2428 | readGeneratedFile(m,tmpI->content,gfile->value); |
---|
2429 | file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char)); |
---|
2430 | for(int i=0;i<strlen(gfile->value);i++) |
---|
2431 | file_name[i]=gfile->value[i+strlen(tmp1->value)]; |
---|
2432 | } |
---|
2433 | |
---|
2434 | toto=getMap(tmpI->content,"asReference"); |
---|
2435 | #ifdef USE_MS |
---|
2436 | if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL) |
---|
2437 | #else |
---|
2438 | if(toto!=NULL && strcasecmp(toto->value,"true")==0) |
---|
2439 | #endif |
---|
2440 | { |
---|
2441 | elements* in=getElements(s->outputs,tmpI->name); |
---|
2442 | char *format=NULL; |
---|
2443 | if(in!=NULL){ |
---|
2444 | format=strdup(in->format); |
---|
2445 | }else |
---|
2446 | format=strdup("LiteralData"); |
---|
2447 | if(strcasecmp(format,"BoundingBoxData")==0){ |
---|
2448 | addToMap(tmpI->content,"extension","xml"); |
---|
2449 | addToMap(tmpI->content,"mimeType","text/xml"); |
---|
2450 | addToMap(tmpI->content,"encoding","UTF-8"); |
---|
2451 | addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); |
---|
2452 | } |
---|
2453 | |
---|
2454 | if(gfile==NULL) { |
---|
2455 | map *ext=getMap(tmpI->content,"extension"); |
---|
2456 | char *file_path; |
---|
2457 | char file_ext[32]; |
---|
2458 | |
---|
2459 | if( ext != NULL && ext->value != NULL) { |
---|
2460 | strncpy(file_ext, ext->value, 32); |
---|
2461 | } |
---|
2462 | else { |
---|
2463 | // Obtain default file extension (see mimetypes.h). |
---|
2464 | // If the MIME type is not recognized, txt is used as the default extension |
---|
2465 | map* mtype=getMap(tmpI->content,"mimeType"); |
---|
2466 | getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); |
---|
2467 | } |
---|
2468 | |
---|
2469 | file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); |
---|
2470 | sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); |
---|
2471 | itn++; |
---|
2472 | file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); |
---|
2473 | sprintf(file_path,"%s/%s",tmp1->value,file_name); |
---|
2474 | |
---|
2475 | FILE *ofile=fopen(file_path,"wb"); |
---|
2476 | if(ofile==NULL){ |
---|
2477 | char tmpMsg[1024]; |
---|
2478 | sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name); |
---|
2479 | errorException(m,tmpMsg,"InternalError",NULL); |
---|
2480 | free(file_name); |
---|
2481 | free(file_path); |
---|
2482 | return; |
---|
2483 | } |
---|
2484 | free(file_path); |
---|
2485 | |
---|
2486 | toto=getMap(tmpI->content,"value"); |
---|
2487 | if(strcasecmp(format,"BoundingBoxData")!=0){ |
---|
2488 | map* size=getMap(tmpI->content,"size"); |
---|
2489 | if(size!=NULL && toto!=NULL) |
---|
2490 | fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); |
---|
2491 | else |
---|
2492 | if(toto!=NULL && toto->value!=NULL) |
---|
2493 | fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); |
---|
2494 | }else{ |
---|
2495 | printBoundingBoxDocument(m,tmpI,ofile); |
---|
2496 | } |
---|
2497 | fclose(ofile); |
---|
2498 | |
---|
2499 | } |
---|
2500 | map *tmp2=getMapFromMaps(m,"main","tmpUrl"); |
---|
2501 | map *tmp3=getMapFromMaps(m,"main","serverAddress"); |
---|
2502 | char *file_url; |
---|
2503 | if(strncasecmp(tmp2->value,"http://",7)==0 || |
---|
2504 | strncasecmp(tmp2->value,"https://",8)==0){ |
---|
2505 | file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); |
---|
2506 | sprintf(file_url,"%s/%s",tmp2->value,file_name); |
---|
2507 | }else{ |
---|
2508 | file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); |
---|
2509 | sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); |
---|
2510 | } |
---|
2511 | addToMap(tmpI->content,"Reference",file_url); |
---|
2512 | free(format); |
---|
2513 | free(file_name); |
---|
2514 | free(file_url); |
---|
2515 | |
---|
2516 | } |
---|
2517 | #ifdef USE_MS |
---|
2518 | else{ |
---|
2519 | if(testMap!=NULL){ |
---|
2520 | setReferenceUrl(m,tmpI); |
---|
2521 | } |
---|
2522 | } |
---|
2523 | #endif |
---|
2524 | tmpI=tmpI->next; |
---|
2525 | } |
---|
2526 | #ifdef DEBUG |
---|
2527 | fprintf(stderr,"SERVICE : %s\n",s->name); |
---|
2528 | dumpMaps(m); |
---|
2529 | #endif |
---|
2530 | printProcessResponse(m,request_inputs1,cpid, |
---|
2531 | s, s->name,res, // replace serviceProvider with serviceName in stored response file name |
---|
2532 | request_inputs, |
---|
2533 | request_outputs); |
---|
2534 | } |
---|
2535 | else{ |
---|
2536 | /** |
---|
2537 | * We get the requested output or fallback to the first one if the |
---|
2538 | * requested one is not present in the resulting outputs maps. |
---|
2539 | */ |
---|
2540 | maps* tmpI=NULL; |
---|
2541 | map* tmpIV=getMap(request_inputs1,"RawDataOutput"); |
---|
2542 | if(tmpIV!=NULL){ |
---|
2543 | tmpI=getMaps(request_outputs,tmpIV->value); |
---|
2544 | } |
---|
2545 | if(tmpI==NULL) |
---|
2546 | tmpI=request_outputs; |
---|
2547 | elements* e=getElements(s->outputs,tmpI->name); |
---|
2548 | if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ |
---|
2549 | printBoundingBoxDocument(m,tmpI,NULL); |
---|
2550 | }else{ |
---|
2551 | map *gfile=getMap(tmpI->content,"generated_file"); |
---|
2552 | if(gfile!=NULL){ |
---|
2553 | gfile=getMap(tmpI->content,"expected_generated_file"); |
---|
2554 | if(gfile==NULL){ |
---|
2555 | gfile=getMap(tmpI->content,"generated_file"); |
---|
2556 | } |
---|
2557 | readGeneratedFile(m,tmpI->content,gfile->value); |
---|
2558 | } |
---|
2559 | toto=getMap(tmpI->content,"value"); |
---|
2560 | if(toto==NULL){ |
---|
2561 | char tmpMsg[1024]; |
---|
2562 | sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name); |
---|
2563 | errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput"); |
---|
2564 | return; |
---|
2565 | } |
---|
2566 | map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); |
---|
2567 | if(fname!=NULL) |
---|
2568 | printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); |
---|
2569 | map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); |
---|
2570 | if(rs!=NULL) |
---|
2571 | printf("Content-Length: %s\r\n",rs->value); |
---|
2572 | printHeaders(m); |
---|
2573 | char mime[1024]; |
---|
2574 | map* mi=getMap(tmpI->content,"mimeType"); |
---|
2575 | #ifdef DEBUG |
---|
2576 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
2577 | dumpMaps(request_outputs); |
---|
2578 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
2579 | #endif |
---|
2580 | map* en=getMap(tmpI->content,"encoding"); |
---|
2581 | if(mi!=NULL && en!=NULL) |
---|
2582 | sprintf(mime, |
---|
2583 | "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", |
---|
2584 | mi->value,en->value); |
---|
2585 | else |
---|
2586 | if(mi!=NULL) |
---|
2587 | sprintf(mime, |
---|
2588 | "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", |
---|
2589 | mi->value); |
---|
2590 | else |
---|
2591 | sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); |
---|
2592 | printf("%s",mime); |
---|
2593 | if(rs!=NULL) |
---|
2594 | fwrite(toto->value,1,atoi(rs->value),stdout); |
---|
2595 | else |
---|
2596 | fwrite(toto->value,1,strlen(toto->value),stdout); |
---|
2597 | #ifdef DEBUG |
---|
2598 | dumpMap(toto); |
---|
2599 | #endif |
---|
2600 | } |
---|
2601 | } |
---|
2602 | } |
---|
2603 | |
---|
2604 | /** |
---|
2605 | * Create required XML nodes for boundingbox and update the current XML node |
---|
2606 | * |
---|
2607 | * @param ns_ows the ows XML namespace |
---|
2608 | * @param n the XML node to update |
---|
2609 | * @param boundingbox the map containing the boundingbox definition |
---|
2610 | */ |
---|
2611 | void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){ |
---|
2612 | |
---|
2613 | xmlNodePtr lw=NULL,uc=NULL; |
---|
2614 | |
---|
2615 | map* tmp=getMap(boundingbox,"value"); |
---|
2616 | |
---|
2617 | tmp=getMap(boundingbox,"lowerCorner"); |
---|
2618 | if(tmp!=NULL){ |
---|
2619 | lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner"); |
---|
2620 | xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value)); |
---|
2621 | } |
---|
2622 | |
---|
2623 | tmp=getMap(boundingbox,"upperCorner"); |
---|
2624 | if(tmp!=NULL){ |
---|
2625 | uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner"); |
---|
2626 | xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value)); |
---|
2627 | } |
---|
2628 | |
---|
2629 | tmp=getMap(boundingbox,"crs"); |
---|
2630 | if(tmp!=NULL) |
---|
2631 | xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value); |
---|
2632 | |
---|
2633 | tmp=getMap(boundingbox,"dimensions"); |
---|
2634 | if(tmp!=NULL) |
---|
2635 | xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value); |
---|
2636 | |
---|
2637 | xmlAddChild(n,lw); |
---|
2638 | xmlAddChild(n,uc); |
---|
2639 | |
---|
2640 | } |
---|
2641 | |
---|
2642 | /** |
---|
2643 | * Parse a BoundingBox string |
---|
2644 | * |
---|
2645 | * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040): |
---|
2646 | * 10.2 Bounding box |
---|
2647 | * |
---|
2648 | * |
---|
2649 | * Value is provided as : lowerCorner,upperCorner,crs,dimension |
---|
2650 | * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84 |
---|
2651 | * |
---|
2652 | * A map to store boundingbox informations should contain: |
---|
2653 | * - lowerCorner : double,double (minimum within this bounding box) |
---|
2654 | * - upperCorner : double,double (maximum within this bounding box) |
---|
2655 | * - crs : URI (Reference to definition of the CRS) |
---|
2656 | * - dimensions : int |
---|
2657 | * |
---|
2658 | * Note : support only 2D bounding box. |
---|
2659 | * |
---|
2660 | * @param value the char* containing the KVP bouding box |
---|
2661 | * @return a map containing all the bounding box keys |
---|
2662 | */ |
---|
2663 | map* parseBoundingBox(const char* value){ |
---|
2664 | map *res=NULL; |
---|
2665 | if(value!=NULL){ |
---|
2666 | char *cv,*cvp; |
---|
2667 | cv=strtok_r((char*) value,",",&cvp); |
---|
2668 | int cnt=0; |
---|
2669 | int icnt=0; |
---|
2670 | char *currentValue=NULL; |
---|
2671 | while(cv){ |
---|
2672 | if(cnt<2) |
---|
2673 | if(currentValue!=NULL){ |
---|
2674 | char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char)); |
---|
2675 | sprintf(finalValue,"%s%s",currentValue,cv); |
---|
2676 | switch(cnt){ |
---|
2677 | case 0: |
---|
2678 | res=createMap("lowerCorner",finalValue); |
---|
2679 | break; |
---|
2680 | case 1: |
---|
2681 | addToMap(res,"upperCorner",finalValue); |
---|
2682 | icnt=-1; |
---|
2683 | break; |
---|
2684 | } |
---|
2685 | cnt++; |
---|
2686 | free(currentValue); |
---|
2687 | currentValue=NULL; |
---|
2688 | free(finalValue); |
---|
2689 | } |
---|
2690 | else{ |
---|
2691 | currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char)); |
---|
2692 | sprintf(currentValue,"%s ",cv); |
---|
2693 | } |
---|
2694 | else |
---|
2695 | if(cnt==2){ |
---|
2696 | addToMap(res,"crs",cv); |
---|
2697 | cnt++; |
---|
2698 | } |
---|
2699 | else |
---|
2700 | addToMap(res,"dimensions",cv); |
---|
2701 | icnt++; |
---|
2702 | cv=strtok_r(NULL,",",&cvp); |
---|
2703 | } |
---|
2704 | } |
---|
2705 | return res; |
---|
2706 | } |
---|
2707 | |
---|
2708 | /** |
---|
2709 | * Print an ows:BoundingBox XML document |
---|
2710 | * |
---|
2711 | * @param m the maps containing the settings of the main.cfg file |
---|
2712 | * @param boundingbox the maps containing the boundingbox definition |
---|
2713 | * @param file the file to print the BoundingBox (if NULL then print on stdout) |
---|
2714 | * @see parseBoundingBox, printBoundingBox |
---|
2715 | */ |
---|
2716 | void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){ |
---|
2717 | if(file==NULL) |
---|
2718 | rewind(stdout); |
---|
2719 | xmlNodePtr n; |
---|
2720 | xmlDocPtr doc; |
---|
2721 | xmlNsPtr ns_ows,ns_xsi; |
---|
2722 | xmlChar *xmlbuff; |
---|
2723 | int buffersize; |
---|
2724 | char *encoding=getEncoding(m); |
---|
2725 | map *tmp; |
---|
2726 | if(file==NULL){ |
---|
2727 | int pid=0; |
---|
2728 | tmp=getMapFromMaps(m,"lenv","sid"); |
---|
2729 | if(tmp!=NULL) |
---|
2730 | pid=atoi(tmp->value); |
---|
2731 | if(pid==getpid()){ |
---|
2732 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
2733 | } |
---|
2734 | fflush(stdout); |
---|
2735 | } |
---|
2736 | |
---|
2737 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
2738 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
2739 | ns_ows=usedNs[owsId]; |
---|
2740 | n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox"); |
---|
2741 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
2742 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
2743 | ns_xsi=usedNs[xsiId]; |
---|
2744 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); |
---|
2745 | map *tmp1=getMap(boundingbox->content,"value"); |
---|
2746 | tmp=parseBoundingBox(tmp1->value); |
---|
2747 | printBoundingBox(ns_ows,n,tmp); |
---|
2748 | xmlDocSetRootElement(doc, n); |
---|
2749 | |
---|
2750 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
2751 | if(file==NULL) |
---|
2752 | printf("%s",xmlbuff); |
---|
2753 | else{ |
---|
2754 | fprintf(file,"%s",xmlbuff); |
---|
2755 | } |
---|
2756 | |
---|
2757 | if(tmp!=NULL){ |
---|
2758 | freeMap(&tmp); |
---|
2759 | free(tmp); |
---|
2760 | } |
---|
2761 | xmlFree(xmlbuff); |
---|
2762 | xmlFreeDoc(doc); |
---|
2763 | xmlCleanupParser(); |
---|
2764 | zooXmlCleanupNs(); |
---|
2765 | |
---|
2766 | } |
---|
2767 | |
---|
2768 | /** |
---|
2769 | * Print a StatusInfo XML document. |
---|
2770 | * a statusInfo map should contain the following keys: |
---|
2771 | * * JobID corresponding to usid key from the lenv section |
---|
2772 | * * Status the current state (Succeeded,Failed,Accepted,Running) |
---|
2773 | * * PercentCompleted (optional) the percent completed |
---|
2774 | * * Message (optional) any messages the service may wish to share |
---|
2775 | * |
---|
2776 | * @param conf the maps containing the settings of the main.cfg file |
---|
2777 | * @param statusInfo the map containing the statusInfo definition |
---|
2778 | * @param req the WPS requests (GetResult, GetStatus or Dismiss) |
---|
2779 | */ |
---|
2780 | void printStatusInfo(maps* conf,map* statusInfo,char* req){ |
---|
2781 | rewind(stdout); |
---|
2782 | xmlNodePtr n,n1; |
---|
2783 | xmlDocPtr doc; |
---|
2784 | xmlNsPtr ns; |
---|
2785 | xmlChar *xmlbuff; |
---|
2786 | int buffersize; |
---|
2787 | char *encoding=getEncoding(conf); |
---|
2788 | map *tmp; |
---|
2789 | int pid=0; |
---|
2790 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
2791 | |
---|
2792 | map* version=getMapFromMaps(conf,"main","rversion"); |
---|
2793 | int vid=getVersionId(version->value); |
---|
2794 | |
---|
2795 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
2796 | n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1); |
---|
2797 | |
---|
2798 | map* val=getMap(statusInfo,"JobID"); |
---|
2799 | int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps"); |
---|
2800 | ns=usedNs[wpsId]; |
---|
2801 | n = xmlNewNode(ns, BAD_CAST "JobID"); |
---|
2802 | xmlAddChild(n,xmlNewText(BAD_CAST val->value)); |
---|
2803 | |
---|
2804 | xmlAddChild(n1,n); |
---|
2805 | |
---|
2806 | val=getMap(statusInfo,"Status"); |
---|
2807 | n = xmlNewNode(ns, BAD_CAST "Status"); |
---|
2808 | xmlAddChild(n,xmlNewText(BAD_CAST val->value)); |
---|
2809 | |
---|
2810 | xmlAddChild(n1,n); |
---|
2811 | |
---|
2812 | if(strncasecmp(val->value,"Failed",6)!=0 && |
---|
2813 | strncasecmp(val->value,"Succeeded",9)!=0){ |
---|
2814 | val=getMap(statusInfo,"PercentCompleted"); |
---|
2815 | if(val!=NULL){ |
---|
2816 | n = xmlNewNode(ns, BAD_CAST "PercentCompleted"); |
---|
2817 | xmlAddChild(n,xmlNewText(BAD_CAST val->value)); |
---|
2818 | xmlAddChild(n1,n); |
---|
2819 | } |
---|
2820 | |
---|
2821 | val=getMap(statusInfo,"Message"); |
---|
2822 | if(val!=NULL){ |
---|
2823 | xmlAddChild(n1,xmlNewComment(BAD_CAST val->value)); |
---|
2824 | } |
---|
2825 | } |
---|
2826 | xmlDocSetRootElement(doc, n1); |
---|
2827 | |
---|
2828 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
2829 | printf("%s",xmlbuff); |
---|
2830 | |
---|
2831 | xmlFree(xmlbuff); |
---|
2832 | xmlFreeDoc(doc); |
---|
2833 | xmlCleanupParser(); |
---|
2834 | zooXmlCleanupNs(); |
---|
2835 | |
---|
2836 | } |
---|
2837 | |
---|