1 | /** |
---|
2 | * Author : Gérald FENOY |
---|
3 | * |
---|
4 | * Copyright (c) 2009-2010 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 "service_internal.h" |
---|
26 | |
---|
27 | void *addLangAttr(xmlNodePtr n,maps *m){ |
---|
28 | map *tmpLmap=getMapFromMaps(m,"main","language"); |
---|
29 | if(tmpLmap!=NULL) |
---|
30 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value); |
---|
31 | else |
---|
32 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US"); |
---|
33 | } |
---|
34 | |
---|
35 | /* Converts a hex character to its integer value */ |
---|
36 | char from_hex(char ch) { |
---|
37 | return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; |
---|
38 | } |
---|
39 | |
---|
40 | /* Converts an integer value to its hex character*/ |
---|
41 | char to_hex(char code) { |
---|
42 | static char hex[] = "0123456789abcdef"; |
---|
43 | return hex[code & 15]; |
---|
44 | } |
---|
45 | |
---|
46 | void* unhandleStatus(maps *conf){ |
---|
47 | int shmid,i; |
---|
48 | key_t key; |
---|
49 | void *shm; |
---|
50 | struct shmid_ds shmids; |
---|
51 | char *s,*s1; |
---|
52 | map *tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
53 | if(tmpMap!=NULL){ |
---|
54 | key=atoi(tmpMap->value); |
---|
55 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
56 | #ifdef DEBUG |
---|
57 | fprintf(stderr,"shmget failed to update value\n"); |
---|
58 | #endif |
---|
59 | }else{ |
---|
60 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
61 | #ifdef DEBUG |
---|
62 | fprintf(stderr,"shmat failed to update value\n"); |
---|
63 | #endif |
---|
64 | }else{ |
---|
65 | shmdt(shm); |
---|
66 | shmctl(shmid,IPC_RMID,&shmids); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | #ifdef USE_JS |
---|
73 | |
---|
74 | JSBool |
---|
75 | JSUpdateStatus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) |
---|
76 | { |
---|
77 | JS_MaybeGC(cx); |
---|
78 | char *sid; |
---|
79 | int istatus=0; |
---|
80 | char *status=NULL; |
---|
81 | maps *conf; |
---|
82 | int i=0; |
---|
83 | if(argc>2){ |
---|
84 | #ifdef JS_DEBUG |
---|
85 | fprintf(stderr,"Number of arguments used to call the function : %i",argc); |
---|
86 | #endif |
---|
87 | return JS_FALSE; |
---|
88 | } |
---|
89 | conf=mapsFromJSObject(cx,argv[0]); |
---|
90 | if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){ |
---|
91 | char tmpStatus[4]; |
---|
92 | sprintf(tmpStatus,"%i",istatus); |
---|
93 | tmpStatus[3]=0; |
---|
94 | status=strdup(tmpStatus); |
---|
95 | } |
---|
96 | if(getMapFromMaps(conf,"lenv","status")!=NULL){ |
---|
97 | if(status!=NULL) |
---|
98 | setMapInMaps(conf,"lenv","status",status); |
---|
99 | else |
---|
100 | setMapInMaps(conf,"lenv","status","15"); |
---|
101 | updateStatus(conf); |
---|
102 | } |
---|
103 | freeMaps(&conf); |
---|
104 | free(conf); |
---|
105 | JS_MaybeGC(cx); |
---|
106 | return JS_TRUE; |
---|
107 | } |
---|
108 | |
---|
109 | #endif |
---|
110 | |
---|
111 | void* updateStatus(maps *conf){ |
---|
112 | int shmid,i; |
---|
113 | key_t key; |
---|
114 | char *shm,*s,*s1; |
---|
115 | map *tmpMap=NULL; |
---|
116 | tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
117 | if(tmpMap!=NULL){ |
---|
118 | key=atoi(tmpMap->value); |
---|
119 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
120 | #ifdef DEBUG |
---|
121 | fprintf(stderr,"shmget failed to update value\n"); |
---|
122 | #endif |
---|
123 | }else{ |
---|
124 | if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
125 | #ifdef DEBUG |
---|
126 | fprintf(stderr,"shmat failed to update value\n"); |
---|
127 | #endif |
---|
128 | } |
---|
129 | else{ |
---|
130 | tmpMap=getMapFromMaps(conf,"lenv","status"); |
---|
131 | s1=shm; |
---|
132 | for(s=tmpMap->value;*s!=NULL;s++) |
---|
133 | *s1++=*s; |
---|
134 | shmdt((void *)shm); |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | char* getStatus(int pid){ |
---|
141 | int shmid,i; |
---|
142 | key_t key; |
---|
143 | void *shm; |
---|
144 | char *s; |
---|
145 | key=pid; |
---|
146 | if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { |
---|
147 | #ifdef DEBUG |
---|
148 | fprintf(stderr,"shmget failed in getStatus\n"); |
---|
149 | #endif |
---|
150 | }else{ |
---|
151 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
152 | #ifdef DEBUG |
---|
153 | fprintf(stderr,"shmat failed in getStatus\n"); |
---|
154 | #endif |
---|
155 | }else{ |
---|
156 | return (char*)shm; |
---|
157 | } |
---|
158 | } |
---|
159 | return "-1"; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | /* Returns a url-encoded version of str */ |
---|
164 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
165 | char *url_encode(char *str) { |
---|
166 | char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf; |
---|
167 | while (*pstr) { |
---|
168 | if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') |
---|
169 | *pbuf++ = *pstr; |
---|
170 | else if (*pstr == ' ') |
---|
171 | *pbuf++ = '+'; |
---|
172 | else |
---|
173 | *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); |
---|
174 | pstr++; |
---|
175 | } |
---|
176 | *pbuf = '\0'; |
---|
177 | return buf; |
---|
178 | } |
---|
179 | |
---|
180 | /* Returns a url-decoded version of str */ |
---|
181 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
182 | char *url_decode(char *str) { |
---|
183 | char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf; |
---|
184 | while (*pstr) { |
---|
185 | if (*pstr == '%') { |
---|
186 | if (pstr[1] && pstr[2]) { |
---|
187 | *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); |
---|
188 | pstr += 2; |
---|
189 | } |
---|
190 | } else if (*pstr == '+') { |
---|
191 | *pbuf++ = ' '; |
---|
192 | } else { |
---|
193 | *pbuf++ = *pstr; |
---|
194 | } |
---|
195 | pstr++; |
---|
196 | } |
---|
197 | *pbuf = '\0'; |
---|
198 | return buf; |
---|
199 | } |
---|
200 | |
---|
201 | char *zCapitalize1(char *tmp){ |
---|
202 | char *res=strdup(tmp); |
---|
203 | if(res[0]>=97 && res[0]<=122) |
---|
204 | res[0]-=32; |
---|
205 | return res; |
---|
206 | } |
---|
207 | |
---|
208 | char *zCapitalize(char *tmp){ |
---|
209 | int i=0; |
---|
210 | char *res=strdup(tmp); |
---|
211 | for(i=0;i<strlen(res);i++) |
---|
212 | if(res[i]>=97 && res[i]<=122) |
---|
213 | res[i]-=32; |
---|
214 | return res; |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | int zooXmlSearchForNs(char* name){ |
---|
219 | int i; |
---|
220 | int res=-1; |
---|
221 | for(i=0;i<nbNs;i++) |
---|
222 | if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){ |
---|
223 | res=i; |
---|
224 | break; |
---|
225 | } |
---|
226 | return res; |
---|
227 | } |
---|
228 | |
---|
229 | int zooXmlAddNs(xmlNodePtr nr,char* url,char* name){ |
---|
230 | #ifdef DEBUG |
---|
231 | fprintf(stderr,"zooXmlAddNs %d \n",nbNs); |
---|
232 | #endif |
---|
233 | int currId=-1; |
---|
234 | if(nbNs==0){ |
---|
235 | nbNs++; |
---|
236 | currId=0; |
---|
237 | nsName[currId]=strdup(name); |
---|
238 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
239 | }else{ |
---|
240 | currId=zooXmlSearchForNs(name); |
---|
241 | if(currId<0){ |
---|
242 | nbNs++; |
---|
243 | currId=nbNs-1; |
---|
244 | nsName[currId]=strdup(name); |
---|
245 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
246 | } |
---|
247 | } |
---|
248 | return currId; |
---|
249 | } |
---|
250 | |
---|
251 | void zooXmlCleanupNs(){ |
---|
252 | int j; |
---|
253 | #ifdef DEBUG |
---|
254 | fprintf(stderr,"zooXmlCleanup %d\n",nbNs); |
---|
255 | #endif |
---|
256 | for(j=nbNs-1;j>=0;j--){ |
---|
257 | #ifdef DEBUG |
---|
258 | fprintf(stderr,"zooXmlCleanup %d\n",j); |
---|
259 | #endif |
---|
260 | if(j==0) |
---|
261 | xmlFreeNs(usedNs[j]); |
---|
262 | free(nsName[j]); |
---|
263 | nbNs--; |
---|
264 | } |
---|
265 | nbNs=0; |
---|
266 | } |
---|
267 | |
---|
268 | xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){ |
---|
269 | |
---|
270 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
271 | xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
272 | xmlChar *xmlbuff; |
---|
273 | int buffersize; |
---|
274 | /** |
---|
275 | * Create the document and its temporary root. |
---|
276 | */ |
---|
277 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
278 | ns=usedNs[wpsId]; |
---|
279 | maps* toto1=getMaps(m,"main"); |
---|
280 | |
---|
281 | n = xmlNewNode(ns, BAD_CAST "Capabilities"); |
---|
282 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
283 | ns_ows=usedNs[owsId]; |
---|
284 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
285 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
286 | ns_xsi=usedNs[xsiId]; |
---|
287 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
288 | ns_xlink=usedNs[xlinkId]; |
---|
289 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd"); |
---|
290 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
291 | addLangAttr(n,m); |
---|
292 | |
---|
293 | if(toto1!=NULL){ |
---|
294 | map* tmp=getMap(toto1->content,"version"); |
---|
295 | if(tmp!=NULL){ |
---|
296 | xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value); |
---|
297 | } |
---|
298 | else |
---|
299 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
300 | } |
---|
301 | else |
---|
302 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
303 | |
---|
304 | char tmp[256]; |
---|
305 | |
---|
306 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); |
---|
307 | maps* tmp4=getMaps(m,"identification"); |
---|
308 | if(tmp4!=NULL){ |
---|
309 | map* tmp2=tmp4->content; |
---|
310 | while(tmp2!=NULL){ |
---|
311 | if(strncasecmp(tmp2->name,"keywords",8)!=0 && |
---|
312 | strncasecmp(tmp2->name,"serverAddress",13)!=0 && |
---|
313 | strncasecmp(tmp2->name,"lang",4)!=0 && |
---|
314 | strncasecmp(tmp2->name,"encoding",8)!=0 && |
---|
315 | strncasecmp(tmp2->name,"version",7)!=0){ |
---|
316 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
317 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
318 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
319 | xmlAddChild(nc,nc1); |
---|
320 | } |
---|
321 | else |
---|
322 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
323 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
324 | char *toto=tmp2->value; |
---|
325 | char buff[256]; |
---|
326 | int i=0; |
---|
327 | int j=0; |
---|
328 | while(toto[i]){ |
---|
329 | if(toto[i]!=',' && toto[i]!=0){ |
---|
330 | buff[j]=toto[i]; |
---|
331 | buff[j+1]=0; |
---|
332 | j++; |
---|
333 | } |
---|
334 | else{ |
---|
335 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
336 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
337 | xmlAddChild(nc1,nc2); |
---|
338 | j=0; |
---|
339 | } |
---|
340 | i++; |
---|
341 | } |
---|
342 | if(strlen(buff)>0){ |
---|
343 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
344 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
345 | xmlAddChild(nc1,nc2); |
---|
346 | } |
---|
347 | xmlAddChild(nc,nc1); |
---|
348 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); |
---|
349 | xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); |
---|
350 | xmlAddChild(nc,nc2); |
---|
351 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); |
---|
352 | xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); |
---|
353 | xmlAddChild(nc,nc2); |
---|
354 | } |
---|
355 | tmp2=tmp2->next; |
---|
356 | } |
---|
357 | } |
---|
358 | else{ |
---|
359 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
360 | return NULL; |
---|
361 | } |
---|
362 | xmlAddChild(n,nc); |
---|
363 | |
---|
364 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); |
---|
365 | nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); |
---|
366 | nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); |
---|
367 | nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); |
---|
368 | nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); |
---|
369 | tmp4=getMaps(m,"provider"); |
---|
370 | if(tmp4!=NULL){ |
---|
371 | map* tmp2=tmp4->content; |
---|
372 | while(tmp2!=NULL){ |
---|
373 | if(strcmp(tmp2->name,"keywords")!=0 && |
---|
374 | strcmp(tmp2->name,"serverAddress")!=0 && |
---|
375 | strcmp(tmp2->name,"lang")!=0){ |
---|
376 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
377 | if(strcmp(tmp2->name,"ProviderName")==0){ |
---|
378 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
379 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
380 | xmlAddChild(nc,nc1); |
---|
381 | } |
---|
382 | else{ |
---|
383 | if(strcmp(tmp2->name,"ProviderSite")==0){ |
---|
384 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
385 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); |
---|
386 | xmlAddChild(nc,nc1); |
---|
387 | } |
---|
388 | else |
---|
389 | if(strcmp(tmp2->name,"IndividualName")==0 || |
---|
390 | strcmp(tmp2->name,"PositionName")==0){ |
---|
391 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
392 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
393 | xmlAddChild(nc3,nc1); |
---|
394 | } |
---|
395 | else |
---|
396 | if(strncmp(tmp2->name,"Phone",5)==0){ |
---|
397 | char *toto=NULL; |
---|
398 | char *toto1=tmp2->name; |
---|
399 | toto=strstr(toto1,"Phone"); |
---|
400 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5); |
---|
401 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
402 | xmlAddChild(nc5,nc1); |
---|
403 | } |
---|
404 | else |
---|
405 | if(strncmp(tmp2->name,"Address",7)==0){ |
---|
406 | char *toto=NULL; |
---|
407 | char *toto1=tmp2->name; |
---|
408 | toto=strstr(toto1,"Address"); |
---|
409 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7); |
---|
410 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
411 | xmlAddChild(nc6,nc1); |
---|
412 | } |
---|
413 | } |
---|
414 | } |
---|
415 | else |
---|
416 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
417 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
418 | char *toto=tmp2->value; |
---|
419 | char buff[256]; |
---|
420 | int i=0; |
---|
421 | int j=0; |
---|
422 | while(toto[i]){ |
---|
423 | if(toto[i]!=',' && toto[i]!=0){ |
---|
424 | buff[j]=toto[i]; |
---|
425 | buff[j+1]=0; |
---|
426 | j++; |
---|
427 | } |
---|
428 | else{ |
---|
429 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
430 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
431 | xmlAddChild(nc1,nc2); |
---|
432 | j=0; |
---|
433 | } |
---|
434 | i++; |
---|
435 | } |
---|
436 | if(strlen(buff)>0){ |
---|
437 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
438 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
439 | xmlAddChild(nc1,nc2); |
---|
440 | } |
---|
441 | xmlAddChild(nc,nc1); |
---|
442 | } |
---|
443 | tmp2=tmp2->next; |
---|
444 | } |
---|
445 | } |
---|
446 | else{ |
---|
447 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
448 | } |
---|
449 | xmlAddChild(nc4,nc5); |
---|
450 | xmlAddChild(nc4,nc6); |
---|
451 | xmlAddChild(nc3,nc4); |
---|
452 | xmlAddChild(nc,nc3); |
---|
453 | xmlAddChild(n,nc); |
---|
454 | |
---|
455 | |
---|
456 | nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); |
---|
457 | char *tmp2[3]; |
---|
458 | tmp2[0]=strdup("GetCapabilities"); |
---|
459 | tmp2[1]=strdup("DescribeProcess"); |
---|
460 | tmp2[2]=strdup("Execute"); |
---|
461 | int j=0; |
---|
462 | |
---|
463 | if(toto1!=NULL){ |
---|
464 | map* tmp=getMap(toto1->content,"serverAddress"); |
---|
465 | if(tmp!=NULL){ |
---|
466 | SERVICE_URL = strdup(tmp->value); |
---|
467 | } |
---|
468 | else |
---|
469 | SERVICE_URL = strdup("not_found"); |
---|
470 | } |
---|
471 | else |
---|
472 | SERVICE_URL = strdup("not_found"); |
---|
473 | |
---|
474 | for(j=0;j<3;j++){ |
---|
475 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); |
---|
476 | xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]); |
---|
477 | nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); |
---|
478 | nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); |
---|
479 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); |
---|
480 | sprintf(tmp,"%s/%s",SERVICE_URL,service); |
---|
481 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
482 | xmlAddChild(nc3,nc4); |
---|
483 | if(j>0){ |
---|
484 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); |
---|
485 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
486 | xmlAddChild(nc3,nc4); |
---|
487 | } |
---|
488 | xmlAddChild(nc2,nc3); |
---|
489 | xmlAddChild(nc1,nc2); |
---|
490 | xmlAddChild(nc,nc1); |
---|
491 | } |
---|
492 | for(j=2;j>=0;j--) |
---|
493 | free(tmp2[j]); |
---|
494 | xmlAddChild(n,nc); |
---|
495 | |
---|
496 | nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); |
---|
497 | xmlAddChild(n,nc); |
---|
498 | |
---|
499 | nc1 = xmlNewNode(ns, BAD_CAST "Languages"); |
---|
500 | nc2 = xmlNewNode(ns, BAD_CAST "Default"); |
---|
501 | nc3 = xmlNewNode(ns, BAD_CAST "Supported"); |
---|
502 | |
---|
503 | toto1=getMaps(m,"main"); |
---|
504 | if(toto1!=NULL){ |
---|
505 | map* tmp1=getMap(toto1->content,"lang"); |
---|
506 | char *toto=tmp1->value; |
---|
507 | char buff[256]; |
---|
508 | int i=0; |
---|
509 | int j=0; |
---|
510 | int dcount=0; |
---|
511 | while(toto[i]){ |
---|
512 | if(toto[i]!=',' && toto[i]!=0){ |
---|
513 | buff[j]=toto[i]; |
---|
514 | buff[j+1]=0; |
---|
515 | j++; |
---|
516 | } |
---|
517 | else{ |
---|
518 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
519 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
520 | if(dcount==0){ |
---|
521 | xmlAddChild(nc2,nc4); |
---|
522 | xmlAddChild(nc1,nc2); |
---|
523 | dcount++; |
---|
524 | } |
---|
525 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
526 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
527 | xmlAddChild(nc3,nc4); |
---|
528 | j=0; |
---|
529 | buff[j]=0; |
---|
530 | } |
---|
531 | i++; |
---|
532 | } |
---|
533 | if(strlen(buff)>0){ |
---|
534 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
535 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
536 | xmlAddChild(nc3,nc4); |
---|
537 | } |
---|
538 | } |
---|
539 | xmlAddChild(nc1,nc3); |
---|
540 | xmlAddChild(n,nc1); |
---|
541 | |
---|
542 | xmlDocSetRootElement(doc, n); |
---|
543 | //xmlFreeNs(ns); |
---|
544 | free(SERVICE_URL); |
---|
545 | return nc; |
---|
546 | } |
---|
547 | |
---|
548 | void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ |
---|
549 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
550 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
551 | /** |
---|
552 | * Initialize or get existing namspaces |
---|
553 | */ |
---|
554 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
555 | ns=usedNs[wpsId]; |
---|
556 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
557 | ns_ows=usedNs[owsId]; |
---|
558 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
559 | ns_xlink=usedNs[xlinkId]; |
---|
560 | |
---|
561 | int cursor=0; |
---|
562 | map* tmp1; |
---|
563 | if(serv->content!=NULL){ |
---|
564 | nc1 = xmlNewNode(ns, BAD_CAST "Process"); |
---|
565 | tmp1=getMap(serv->content,"processVersion"); |
---|
566 | if(tmp1!=NULL) |
---|
567 | xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
568 | printDescription(nc1,ns_ows,serv->name,serv->content); |
---|
569 | tmp1=serv->metadata; |
---|
570 | while(tmp1!=NULL){ |
---|
571 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
572 | xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
573 | xmlAddChild(nc1,nc2); |
---|
574 | tmp1=tmp1->next; |
---|
575 | } |
---|
576 | xmlAddChild(nc,nc1); |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){ |
---|
581 | |
---|
582 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
583 | xmlNodePtr n,nr; |
---|
584 | xmlChar *xmlbuff; |
---|
585 | int buffersize; |
---|
586 | |
---|
587 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
588 | ns=usedNs[wpsId]; |
---|
589 | n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions"); |
---|
590 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
591 | ns_ows=usedNs[owsId]; |
---|
592 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
593 | zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
594 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
595 | ns_xsi=usedNs[xsiId]; |
---|
596 | |
---|
597 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd"); |
---|
598 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
599 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
600 | addLangAttr(n,m); |
---|
601 | |
---|
602 | xmlDocSetRootElement(doc, n); |
---|
603 | |
---|
604 | return n; |
---|
605 | } |
---|
606 | |
---|
607 | void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){ |
---|
608 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
609 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
610 | |
---|
611 | char tmp[256]; |
---|
612 | n=nc; |
---|
613 | |
---|
614 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
615 | ns=usedNs[wpsId]; |
---|
616 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
617 | ns_ows=usedNs[owsId]; |
---|
618 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
619 | ns_xlink=usedNs[xlinkId]; |
---|
620 | |
---|
621 | nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); |
---|
622 | char *tmp4[3]; |
---|
623 | tmp4[0]="processVersion"; |
---|
624 | tmp4[1]="storeSupported"; |
---|
625 | tmp4[2]="statusSupported"; |
---|
626 | int j=0; |
---|
627 | map* tmp1=NULL; |
---|
628 | for(j=0;j<3;j++){ |
---|
629 | tmp1=getMap(serv->content,tmp4[j]); |
---|
630 | if(tmp1!=NULL){ |
---|
631 | if(j==0) |
---|
632 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
633 | else |
---|
634 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value); |
---|
635 | } |
---|
636 | else{ |
---|
637 | if(j>0) |
---|
638 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
643 | |
---|
644 | tmp1=serv->metadata; |
---|
645 | while(tmp1!=NULL){ |
---|
646 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
647 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
648 | xmlAddChild(nc,nc1); |
---|
649 | tmp1=tmp1->next; |
---|
650 | } |
---|
651 | |
---|
652 | tmp1=getMap(serv->content,"Profile"); |
---|
653 | if(tmp1!=NULL){ |
---|
654 | nc1 = xmlNewNode(ns, BAD_CAST "Profile"); |
---|
655 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); |
---|
656 | xmlAddChild(nc,nc1); |
---|
657 | } |
---|
658 | |
---|
659 | nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); |
---|
660 | |
---|
661 | elements* e=serv->inputs; |
---|
662 | while(e!=NULL){ |
---|
663 | nc2 = xmlNewNode(NULL, BAD_CAST "Input"); |
---|
664 | tmp1=getMap(e->content,"minOccurs"); |
---|
665 | if(tmp1){ |
---|
666 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
667 | } |
---|
668 | tmp1=getMap(e->content,"maxOccurs"); |
---|
669 | if(tmp1){ |
---|
670 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
671 | } |
---|
672 | |
---|
673 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
674 | |
---|
675 | |
---|
676 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
677 | iotype* _tmp=e->defaults; |
---|
678 | int datatype=0; |
---|
679 | if(_tmp!=NULL){ |
---|
680 | int isAnyValue=1; |
---|
681 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
682 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
683 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
684 | } |
---|
685 | else{ |
---|
686 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
687 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
688 | datatype=1; |
---|
689 | } |
---|
690 | tmp1=_tmp->content; |
---|
691 | int default1=0; |
---|
692 | xmlNodePtr nc7; |
---|
693 | while(tmp1!=NULL){ |
---|
694 | #ifdef DEBUG |
---|
695 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
696 | #endif |
---|
697 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
698 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
699 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
700 | char tmp[1024]; |
---|
701 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
702 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
703 | xmlAddChild(nc3,nc6); |
---|
704 | tmp1=tmp1->next; |
---|
705 | continue; |
---|
706 | } |
---|
707 | if(strcasecmp(tmp1->name,"asReference")!=0 && |
---|
708 | strcasecmp(tmp1->name,"DataType")!=0 && |
---|
709 | strncasecmp(tmp1->name,"AllowedValues",13)!=0 && |
---|
710 | strcasecmp(tmp1->name,"value")!=0 && |
---|
711 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
712 | if(datatype==0){ |
---|
713 | char *tmp2=zCapitalize1(tmp1->name); |
---|
714 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
715 | free(tmp2); |
---|
716 | } |
---|
717 | else{ |
---|
718 | char *tmp2=zCapitalize(tmp1->name); |
---|
719 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
720 | free(tmp2); |
---|
721 | } |
---|
722 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
723 | xmlAddChild(nc5,nc6); |
---|
724 | } |
---|
725 | else{ |
---|
726 | if(strcmp(tmp1->name,"value")==0){ |
---|
727 | nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); |
---|
728 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
729 | default1=1; |
---|
730 | } |
---|
731 | if(strncasecmp(tmp1->name,"AllowedValues",13)==0){ |
---|
732 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
733 | char *token,*saveptr1; |
---|
734 | token=strtok_r(tmp1->value,",",&saveptr1); |
---|
735 | while(token!=NULL){ |
---|
736 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
737 | char *tmps=strdup(token); |
---|
738 | tmps[strlen(tmps)]=0; |
---|
739 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); |
---|
740 | fprintf(stderr,"strgin : %s\n",tmps); |
---|
741 | xmlAddChild(nc6,nc7); |
---|
742 | token=strtok_r(NULL,",",&saveptr1); |
---|
743 | } |
---|
744 | xmlAddChild(nc3,nc6); |
---|
745 | isAnyValue=-1; |
---|
746 | } |
---|
747 | } |
---|
748 | tmp1=tmp1->next; |
---|
749 | } |
---|
750 | xmlAddChild(nc4,nc5); |
---|
751 | xmlAddChild(nc3,nc4); |
---|
752 | if(datatype==1 && isAnyValue==1){ |
---|
753 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
754 | if(default1>0) |
---|
755 | xmlAddChild(nc3,nc7); |
---|
756 | } |
---|
757 | if(datatype==1 && default1>0) |
---|
758 | xmlAddChild(nc3,nc7); |
---|
759 | } |
---|
760 | xmlAddChild(nc2,nc3); |
---|
761 | |
---|
762 | _tmp=e->supported; |
---|
763 | while(_tmp!=NULL){ |
---|
764 | if(datatype==0){ |
---|
765 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
766 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
767 | } |
---|
768 | else{ |
---|
769 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
770 | } |
---|
771 | tmp1=_tmp->content; |
---|
772 | while(tmp1!=NULL){ |
---|
773 | /*if(strcmp(e->format,"LiteralData")==0) |
---|
774 | xmlAddChild(nc5,nc6);*/ |
---|
775 | if(datatype==0){ |
---|
776 | char *tmp2=zCapitalize1(tmp1->name); |
---|
777 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
778 | free(tmp2); |
---|
779 | } |
---|
780 | else{ |
---|
781 | char *tmp2=zCapitalize(tmp1->name); |
---|
782 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
783 | free(tmp2); |
---|
784 | } |
---|
785 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
786 | xmlAddChild(nc5,nc6); |
---|
787 | tmp1=tmp1->next; |
---|
788 | } |
---|
789 | if(datatype==0){ |
---|
790 | xmlAddChild(nc4,nc5); |
---|
791 | xmlAddChild(nc3,nc4); |
---|
792 | }else{ |
---|
793 | xmlAddChild(nc4,nc5); |
---|
794 | //xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
795 | } |
---|
796 | _tmp=_tmp->next; |
---|
797 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
798 | xmlAddChild(nc2,nc3); |
---|
799 | } |
---|
800 | xmlAddChild(nc1,nc2); |
---|
801 | } |
---|
802 | |
---|
803 | |
---|
804 | e=e->next; |
---|
805 | } |
---|
806 | xmlAddChild(nc,nc1); |
---|
807 | |
---|
808 | nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); |
---|
809 | |
---|
810 | e=serv->outputs; |
---|
811 | while(e!=NULL){ |
---|
812 | nc2 = xmlNewNode(NULL, BAD_CAST "Output"); |
---|
813 | tmp1=getMap(e->content,"minOccurs"); |
---|
814 | if(tmp1){ |
---|
815 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
816 | } |
---|
817 | tmp1=getMap(e->content,"maxOccurs"); |
---|
818 | if(tmp1){ |
---|
819 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
820 | } |
---|
821 | |
---|
822 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
823 | |
---|
824 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) |
---|
825 | nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput"); |
---|
826 | else |
---|
827 | if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
828 | nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput"); |
---|
829 | else |
---|
830 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
831 | iotype* _tmp=e->defaults; |
---|
832 | int datatype=0; |
---|
833 | if(_tmp!=NULL){ |
---|
834 | if(strcmp(e->format,"LiteralOutput")==0 || |
---|
835 | strcmp(e->format,"LiteralData")==0){ |
---|
836 | datatype=1; |
---|
837 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
838 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
839 | } |
---|
840 | else{ |
---|
841 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
842 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
843 | } |
---|
844 | tmp1=_tmp->content; |
---|
845 | while(tmp1!=NULL){ |
---|
846 | #ifdef DEBUG |
---|
847 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
848 | #endif |
---|
849 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
850 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
851 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
852 | char tmp[1024]; |
---|
853 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
854 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
855 | xmlAddChild(nc3,nc6); |
---|
856 | tmp1=tmp1->next; |
---|
857 | datatype=1; |
---|
858 | continue; |
---|
859 | } |
---|
860 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
861 | strncasecmp(tmp1->name,"DataType",8)!=0 && |
---|
862 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
863 | if(datatype==0){ |
---|
864 | char *tmp2=zCapitalize1(tmp1->name); |
---|
865 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
866 | free(tmp2); |
---|
867 | } |
---|
868 | else{ |
---|
869 | char *tmp2=zCapitalize(tmp1->name); |
---|
870 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
871 | free(tmp2); |
---|
872 | } |
---|
873 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
874 | xmlAddChild(nc5,nc6); |
---|
875 | } |
---|
876 | tmp1=tmp1->next; |
---|
877 | } |
---|
878 | xmlAddChild(nc4,nc5); |
---|
879 | xmlAddChild(nc3,nc4); |
---|
880 | } |
---|
881 | _tmp=e->supported; |
---|
882 | while(_tmp!=NULL){ |
---|
883 | if(datatype==0){ |
---|
884 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
885 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
886 | } |
---|
887 | else |
---|
888 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
889 | tmp1=_tmp->content; |
---|
890 | while(tmp1!=NULL){ |
---|
891 | #ifdef DEBUG |
---|
892 | printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); |
---|
893 | #endif |
---|
894 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
895 | strcmp(tmp1->name,"DataType")!=0 && |
---|
896 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
897 | if(datatype==0){ |
---|
898 | char *tmp2=zCapitalize1(tmp1->name); |
---|
899 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
900 | free(tmp2); |
---|
901 | } |
---|
902 | else{ |
---|
903 | char *tmp2=zCapitalize(tmp1->name); |
---|
904 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
905 | free(tmp2); |
---|
906 | } |
---|
907 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
908 | xmlAddChild(nc5,nc6); |
---|
909 | } |
---|
910 | tmp1=tmp1->next; |
---|
911 | } |
---|
912 | _tmp=_tmp->next; |
---|
913 | if(datatype==0){ |
---|
914 | xmlAddChild(nc4,nc5); |
---|
915 | xmlAddChild(nc3,nc4); |
---|
916 | }else |
---|
917 | xmlAddChild(nc4,nc5); |
---|
918 | } |
---|
919 | xmlAddChild(nc2,nc3); |
---|
920 | |
---|
921 | xmlAddChild(nc3,nc4); |
---|
922 | |
---|
923 | |
---|
924 | xmlAddChild(nc2,nc3); |
---|
925 | |
---|
926 | xmlAddChild(nc1,nc2); |
---|
927 | |
---|
928 | e=e->next; |
---|
929 | } |
---|
930 | xmlAddChild(nc,nc1); |
---|
931 | |
---|
932 | xmlAddChild(n,nc); |
---|
933 | |
---|
934 | } |
---|
935 | |
---|
936 | void printProcessResponse(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){ |
---|
937 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
938 | xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor; |
---|
939 | xmlDocPtr doc; |
---|
940 | xmlChar *xmlbuff; |
---|
941 | int buffersize; |
---|
942 | time_t time1; |
---|
943 | time(&time1); |
---|
944 | /** |
---|
945 | * Create the document and its temporary root. |
---|
946 | */ |
---|
947 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
948 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
949 | ns=usedNs[wpsId]; |
---|
950 | |
---|
951 | n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); |
---|
952 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
953 | ns_ows=usedNs[owsId]; |
---|
954 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
955 | ns_xlink=usedNs[xlinkId]; |
---|
956 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
957 | ns_xsi=usedNs[xsiId]; |
---|
958 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
959 | |
---|
960 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd"); |
---|
961 | |
---|
962 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
963 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
964 | addLangAttr(n,m); |
---|
965 | |
---|
966 | char tmp[256]; |
---|
967 | char url[1024]; |
---|
968 | memset(tmp,0,256); |
---|
969 | memset(url,0,256); |
---|
970 | maps* tmp_maps=getMaps(m,"main"); |
---|
971 | if(tmp_maps!=NULL){ |
---|
972 | map* tmpm1=getMap(tmp_maps->content,"serverAddress"); |
---|
973 | /** |
---|
974 | * Check if the ZOO Service GetStatus is available in the local directory. |
---|
975 | * If yes, then it uses a reference to an URL which the client can access |
---|
976 | * to get information on the status of a running Service (using the |
---|
977 | * percentCompleted attribute). |
---|
978 | * Else fallback to the initial method using the xml file to write in ... |
---|
979 | */ |
---|
980 | char ntmp[1024]; |
---|
981 | #ifndef WIN32 |
---|
982 | getcwd(ntmp,1024); |
---|
983 | #else |
---|
984 | _getcwd(ntmp,1024); |
---|
985 | #endif |
---|
986 | struct stat myFileInfo; |
---|
987 | int statRes; |
---|
988 | char file_path[1024]; |
---|
989 | sprintf(file_path,"%s/GetStatus.zcfg",ntmp); |
---|
990 | statRes=stat(file_path,&myFileInfo); |
---|
991 | if(statRes==0){ |
---|
992 | char currentSid[128]; |
---|
993 | map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); |
---|
994 | map *tmp_lenv=NULL; |
---|
995 | tmp_lenv=getMapFromMaps(m,"lenv","sid"); |
---|
996 | if(tmp_lenv==NULL) |
---|
997 | sprintf(currentSid,"%i",pid); |
---|
998 | else |
---|
999 | sprintf(currentSid,"%s",tmp_lenv->value); |
---|
1000 | if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ |
---|
1001 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1002 | }else{ |
---|
1003 | if(strlen(tmpm->value)>0) |
---|
1004 | if(strcasecmp(tmpm->value,"true")!=0) |
---|
1005 | sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); |
---|
1006 | else |
---|
1007 | sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); |
---|
1008 | else |
---|
1009 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1010 | } |
---|
1011 | }else{ |
---|
1012 | map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); |
---|
1013 | if(tmpm1!=NULL && tmpm2!=NULL){ |
---|
1014 | sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); |
---|
1015 | } |
---|
1016 | } |
---|
1017 | if(tmpm1!=NULL) |
---|
1018 | sprintf(tmp,"%s/",tmpm1->value); |
---|
1019 | } |
---|
1020 | |
---|
1021 | xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); |
---|
1022 | if(status!=SERVICE_SUCCEEDED && status!=SERVICE_FAILED){ |
---|
1023 | xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); |
---|
1024 | } |
---|
1025 | |
---|
1026 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
1027 | map* tmp2=getMap(serv->content,"processVersion"); |
---|
1028 | |
---|
1029 | if(tmp2!=NULL) |
---|
1030 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); |
---|
1031 | |
---|
1032 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
1033 | fflush(stderr); |
---|
1034 | |
---|
1035 | xmlAddChild(n,nc); |
---|
1036 | |
---|
1037 | nc = xmlNewNode(ns, BAD_CAST "Status"); |
---|
1038 | const struct tm *tm; |
---|
1039 | size_t len; |
---|
1040 | time_t now; |
---|
1041 | char *tmp1; |
---|
1042 | map *tmpStatus; |
---|
1043 | |
---|
1044 | now = time ( NULL ); |
---|
1045 | tm = localtime ( &now ); |
---|
1046 | |
---|
1047 | tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); |
---|
1048 | |
---|
1049 | len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); |
---|
1050 | |
---|
1051 | xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); |
---|
1052 | |
---|
1053 | char sMsg[2048]; |
---|
1054 | switch(status){ |
---|
1055 | case SERVICE_SUCCEEDED: |
---|
1056 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); |
---|
1057 | sprintf(sMsg,_("Service \"%s\" run successfully."),serv->name); |
---|
1058 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1059 | xmlAddChild(nc1,nc3); |
---|
1060 | break; |
---|
1061 | case SERVICE_STARTED: |
---|
1062 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); |
---|
1063 | tmpStatus=getMapFromMaps(m,"lenv","status"); |
---|
1064 | xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); |
---|
1065 | sprintf(sMsg,_("ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service."),serv->name); |
---|
1066 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1067 | xmlAddChild(nc1,nc3); |
---|
1068 | break; |
---|
1069 | case SERVICE_ACCEPTED: |
---|
1070 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); |
---|
1071 | sprintf(sMsg,_("Service \"%s\" was accepted by the ZOO Kernel and it run as a background task. Please consult the statusLocation attribtue providen in this document to get the up-to-date document."),serv->name); |
---|
1072 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1073 | xmlAddChild(nc1,nc3); |
---|
1074 | break; |
---|
1075 | case SERVICE_FAILED: |
---|
1076 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); |
---|
1077 | map *errorMap; |
---|
1078 | map *te; |
---|
1079 | te=getMapFromMaps(m,"lenv","code"); |
---|
1080 | if(te!=NULL) |
---|
1081 | errorMap=createMap("code",te->value); |
---|
1082 | else |
---|
1083 | errorMap=createMap("code","NoApplicableCode"); |
---|
1084 | te=getMapFromMaps(m,"lenv","message"); |
---|
1085 | if(te!=NULL) |
---|
1086 | addToMap(errorMap,"text",te->value); |
---|
1087 | else |
---|
1088 | addToMap(errorMap,"text",_("No more information available")); |
---|
1089 | nc3=createExceptionReportNode(m,errorMap,0); |
---|
1090 | xmlAddChild(nc1,nc3); |
---|
1091 | break; |
---|
1092 | default : |
---|
1093 | printf(_("error code not know : %i\n"),status); |
---|
1094 | //exit(1); |
---|
1095 | break; |
---|
1096 | } |
---|
1097 | xmlAddChild(nc,nc1); |
---|
1098 | xmlAddChild(n,nc); |
---|
1099 | free(tmp1); |
---|
1100 | |
---|
1101 | #ifdef DEBUG |
---|
1102 | fprintf(stderr,"printProcessResponse 1 161\n"); |
---|
1103 | #endif |
---|
1104 | |
---|
1105 | map* lineage=getMap(request,"lineage"); |
---|
1106 | if(lineage!=NULL){ |
---|
1107 | nc = xmlNewNode(ns, BAD_CAST "DataInputs"); |
---|
1108 | int i; |
---|
1109 | maps* mcursor=inputs; |
---|
1110 | elements* scursor=serv->inputs; |
---|
1111 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
1112 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Input"); |
---|
1113 | mcursor=mcursor->next; |
---|
1114 | //scursor=scursor->next; |
---|
1115 | } |
---|
1116 | xmlAddChild(n,nc); |
---|
1117 | |
---|
1118 | #ifdef DEBUG |
---|
1119 | fprintf(stderr,"printProcessResponse 1 177\n"); |
---|
1120 | #endif |
---|
1121 | |
---|
1122 | nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); |
---|
1123 | mcursor=outputs; |
---|
1124 | scursor=serv->outputs; |
---|
1125 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
1126 | printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
1127 | mcursor=mcursor->next; |
---|
1128 | //scursor=scursor->next; |
---|
1129 | } |
---|
1130 | xmlAddChild(n,nc); |
---|
1131 | } |
---|
1132 | #ifdef DEBUG |
---|
1133 | fprintf(stderr,"printProcessResponse 1 190\n"); |
---|
1134 | #endif |
---|
1135 | |
---|
1136 | /** |
---|
1137 | * Display the process output only when requested ! |
---|
1138 | */ |
---|
1139 | if(status==SERVICE_SUCCEEDED){ |
---|
1140 | nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); |
---|
1141 | maps* mcursor=outputs; |
---|
1142 | elements* scursor=serv->outputs; |
---|
1143 | while(mcursor!=NULL && scursor!=NULL){ |
---|
1144 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
1145 | mcursor=mcursor->next; |
---|
1146 | scursor=scursor->next; |
---|
1147 | } |
---|
1148 | xmlAddChild(n,nc); |
---|
1149 | } |
---|
1150 | #ifdef DEBUG |
---|
1151 | fprintf(stderr,"printProcessResponse 1 202\n"); |
---|
1152 | #endif |
---|
1153 | xmlDocSetRootElement(doc, n); |
---|
1154 | printDocument(m,doc,pid); |
---|
1155 | |
---|
1156 | xmlCleanupParser(); |
---|
1157 | zooXmlCleanupNs(); |
---|
1158 | } |
---|
1159 | |
---|
1160 | |
---|
1161 | void printDocument(maps* m, xmlDocPtr doc,int pid){ |
---|
1162 | rewind(stdout); |
---|
1163 | char *encoding=getEncoding(m); |
---|
1164 | if(pid==getpid()){ |
---|
1165 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1166 | } |
---|
1167 | fflush(stdout); |
---|
1168 | xmlChar *xmlbuff; |
---|
1169 | int buffersize; |
---|
1170 | /* |
---|
1171 | * Dump the document to a buffer and print it on stdout |
---|
1172 | * for demonstration purposes. |
---|
1173 | */ |
---|
1174 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
1175 | printf((char *) xmlbuff); |
---|
1176 | //fflush(stdout); |
---|
1177 | /* |
---|
1178 | * Free associated memory. |
---|
1179 | */ |
---|
1180 | xmlFree(xmlbuff); |
---|
1181 | xmlFreeDoc(doc); |
---|
1182 | xmlCleanupParser(); |
---|
1183 | zooXmlCleanupNs(); |
---|
1184 | } |
---|
1185 | |
---|
1186 | void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
1187 | xmlNodePtr nc1; |
---|
1188 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1189 | map *tmp=NULL; |
---|
1190 | if(e!=NULL && e->defaults!=NULL) |
---|
1191 | tmp=e->defaults->content; |
---|
1192 | else{ |
---|
1193 | /* |
---|
1194 | dumpElements(e); |
---|
1195 | */ |
---|
1196 | return; |
---|
1197 | } |
---|
1198 | while(tmp!=NULL){ |
---|
1199 | if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 |
---|
1200 | || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 |
---|
1201 | || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 |
---|
1202 | || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) |
---|
1203 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1204 | tmp=tmp->next; |
---|
1205 | } |
---|
1206 | tmp=getMap(e->defaults->content,"asReference"); |
---|
1207 | if(tmp==NULL) |
---|
1208 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
1209 | |
---|
1210 | tmp=e->content; |
---|
1211 | |
---|
1212 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
1213 | |
---|
1214 | xmlAddChild(nc,nc1); |
---|
1215 | |
---|
1216 | } |
---|
1217 | |
---|
1218 | void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){ |
---|
1219 | xmlNodePtr nc1,nc2,nc3; |
---|
1220 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1221 | map *tmp=NULL; |
---|
1222 | if(e!=NULL && e->defaults!=NULL) |
---|
1223 | tmp=e->defaults->content; |
---|
1224 | else{ |
---|
1225 | /* |
---|
1226 | dumpElements(e); |
---|
1227 | */ |
---|
1228 | return; |
---|
1229 | } |
---|
1230 | while(tmp!=NULL){ |
---|
1231 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1232 | tmp=tmp->next; |
---|
1233 | } |
---|
1234 | tmp=getMap(e->defaults->content,"asReference"); |
---|
1235 | if(tmp==NULL) |
---|
1236 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
1237 | |
---|
1238 | tmp=e->content; |
---|
1239 | |
---|
1240 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
1241 | |
---|
1242 | xmlAddChild(nc,nc1); |
---|
1243 | |
---|
1244 | } |
---|
1245 | |
---|
1246 | void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
1247 | xmlNodePtr nc1,nc2,nc3; |
---|
1248 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1249 | map *tmp=e->content; |
---|
1250 | #ifdef DEBUG |
---|
1251 | dumpMap(tmp); |
---|
1252 | dumpElements(e); |
---|
1253 | #endif |
---|
1254 | nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
1255 | nc3=xmlNewText(BAD_CAST e->name); |
---|
1256 | xmlAddChild(nc2,nc3); |
---|
1257 | xmlAddChild(nc1,nc2); |
---|
1258 | xmlAddChild(nc,nc1); |
---|
1259 | // Extract Title required to be first element in the ZCFG file ! |
---|
1260 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1261 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1262 | xmlAddChild(nc2,nc3); |
---|
1263 | xmlAddChild(nc1,nc2); |
---|
1264 | // Extract Abstract required to be second element in the ZCFG file ! |
---|
1265 | // For GRASS it can be empty ... |
---|
1266 | if(tmp->next!=NULL){ |
---|
1267 | tmp=tmp->next; |
---|
1268 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1269 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1270 | xmlAddChild(nc2,nc3); |
---|
1271 | xmlAddChild(nc1,nc2); |
---|
1272 | xmlAddChild(nc,nc1); |
---|
1273 | tmp=tmp->next; |
---|
1274 | } |
---|
1275 | |
---|
1276 | /** |
---|
1277 | * IO type Reference or full Data ? |
---|
1278 | */ |
---|
1279 | #ifdef DEBUG |
---|
1280 | fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); |
---|
1281 | #endif |
---|
1282 | map *tmpMap=getMap(m->content,"Reference"); |
---|
1283 | if(tmpMap==NULL){ |
---|
1284 | nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); |
---|
1285 | if(strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0) |
---|
1286 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
1287 | else |
---|
1288 | if(strncasecmp(e->format,"COMPLEXOUTPUT",strlen(e->format))==0) |
---|
1289 | nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); |
---|
1290 | else |
---|
1291 | nc3=xmlNewNode(ns_wps, BAD_CAST e->format); |
---|
1292 | tmp=m->content; |
---|
1293 | while(tmp!=NULL){ |
---|
1294 | if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 && |
---|
1295 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1296 | strncasecmp(tmp->name,"asReference",strlen(tmp->name))!=0 && |
---|
1297 | strncasecmp(tmp->name,"status",strlen(tmp->name))!=0 && |
---|
1298 | strncasecmp(tmp->name,"storeExecuteResponse",strlen(tmp->name))!=0 && |
---|
1299 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0) |
---|
1300 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1301 | tmp=tmp->next; |
---|
1302 | xmlAddChild(nc2,nc3); |
---|
1303 | } |
---|
1304 | tmp=getMap(e->defaults->content,"mimeType"); |
---|
1305 | map* tmp1=getMap(m->content,"encoding"); |
---|
1306 | map* tmp2=getMap(m->content,"mimeType"); |
---|
1307 | map* toto=getMap(m->content,"value"); |
---|
1308 | if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) |
---|
1309 | || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 |
---|
1310 | || strncmp(tmp2->value,"application/",6)==0)) ){ |
---|
1311 | map* rs=getMap(m->content,"size"); |
---|
1312 | if(rs==NULL){ |
---|
1313 | char tmp1[1024]; |
---|
1314 | sprintf(tmp1,"%d",strlen(toto->value)); |
---|
1315 | rs=createMap("z",tmp1); |
---|
1316 | } |
---|
1317 | xmlAddChild(nc3,xmlNewText(BAD_CAST base64((const unsigned char*)toto->value,atoi(rs->value)))); |
---|
1318 | } |
---|
1319 | else if(tmp!=NULL){ |
---|
1320 | if(strncmp(tmp->value,"text/js",4)==0 || |
---|
1321 | strncmp(tmp->value,"application/js",14)==0) |
---|
1322 | xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value))); |
---|
1323 | else |
---|
1324 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
1325 | xmlAddChild(nc2,nc3); |
---|
1326 | } |
---|
1327 | else |
---|
1328 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
1329 | } |
---|
1330 | else{ |
---|
1331 | nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); |
---|
1332 | xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
1333 | tmp=m->content; |
---|
1334 | while(tmp!=NULL){ |
---|
1335 | if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 && |
---|
1336 | strncasecmp(tmp->name,"reference",strlen(tmp->name))!=0 && |
---|
1337 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1338 | strncasecmp(tmp->name,"abstract",strlen(tmp->name))!=0 && |
---|
1339 | strncasecmp(tmp->name,"status",strlen(tmp->name))!=0 && |
---|
1340 | strncasecmp(tmp->name,"storeExecuteResponse",strlen(tmp->name))!=0 && |
---|
1341 | strncasecmp(tmp->name,"asReference",strlen(tmp->name))!=0) |
---|
1342 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1343 | tmp=tmp->next; |
---|
1344 | xmlAddChild(nc2,nc3); |
---|
1345 | } |
---|
1346 | } |
---|
1347 | |
---|
1348 | xmlAddChild(nc1,nc2); |
---|
1349 | xmlAddChild(nc,nc1); |
---|
1350 | |
---|
1351 | } |
---|
1352 | |
---|
1353 | void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){ |
---|
1354 | xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
1355 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
1356 | xmlAddChild(root,nc2); |
---|
1357 | map* tmp=amap; |
---|
1358 | char *tmp2[2]; |
---|
1359 | tmp2[0]="Title"; |
---|
1360 | tmp2[1]="Abstract"; |
---|
1361 | int j=0; |
---|
1362 | for(j=0;j<2;j++){ |
---|
1363 | map* tmp1=getMap(tmp,tmp2[j]); |
---|
1364 | if(tmp1!=NULL){ |
---|
1365 | nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); |
---|
1366 | fprintf(stderr,"[%s] \n[%s]\n",tmp1->value,_ss(tmp1->value)); |
---|
1367 | xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); |
---|
1368 | xmlAddChild(root,nc2); |
---|
1369 | } |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | char* getEncoding(maps* m){ |
---|
1374 | if(m!=NULL){ |
---|
1375 | map* tmp=getMap(m->content,"encoding"); |
---|
1376 | if(tmp!=NULL){ |
---|
1377 | return tmp->value; |
---|
1378 | } |
---|
1379 | else |
---|
1380 | return "UTF-8"; |
---|
1381 | } |
---|
1382 | else |
---|
1383 | return "UTF-8"; |
---|
1384 | } |
---|
1385 | |
---|
1386 | char* getVersion(maps* m){ |
---|
1387 | if(m!=NULL){ |
---|
1388 | map* tmp=getMap(m->content,"version"); |
---|
1389 | if(tmp!=NULL){ |
---|
1390 | return tmp->value; |
---|
1391 | } |
---|
1392 | else |
---|
1393 | return "1.0.0"; |
---|
1394 | } |
---|
1395 | else |
---|
1396 | return "1.0.0"; |
---|
1397 | } |
---|
1398 | |
---|
1399 | void printExceptionReportResponse(maps* m,map* s){ |
---|
1400 | |
---|
1401 | int buffersize; |
---|
1402 | xmlDocPtr doc; |
---|
1403 | xmlChar *xmlbuff; |
---|
1404 | xmlNodePtr n; |
---|
1405 | |
---|
1406 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
1407 | maps* tmpMap=getMaps(m,"main"); |
---|
1408 | char *encoding=getEncoding(tmpMap); |
---|
1409 | if(m!=NULL){ |
---|
1410 | map *tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
1411 | if(tmpSid!=NULL){ |
---|
1412 | if( getpid()==atoi(tmpSid->value) ) |
---|
1413 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1414 | } |
---|
1415 | else |
---|
1416 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1417 | }else |
---|
1418 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1419 | n=createExceptionReportNode(m,s,1); |
---|
1420 | xmlDocSetRootElement(doc, n); |
---|
1421 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
1422 | printf("%s",xmlbuff); |
---|
1423 | fflush(stdout); |
---|
1424 | xmlFreeDoc(doc); |
---|
1425 | xmlFree(xmlbuff); |
---|
1426 | xmlCleanupParser(); |
---|
1427 | } |
---|
1428 | |
---|
1429 | xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ |
---|
1430 | |
---|
1431 | int buffersize; |
---|
1432 | xmlChar *xmlbuff; |
---|
1433 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
1434 | xmlNodePtr n,nc,nc1,nc2; |
---|
1435 | |
---|
1436 | maps* tmpMap=getMaps(m,"main"); |
---|
1437 | |
---|
1438 | ns=xmlNewNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
1439 | n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); |
---|
1440 | |
---|
1441 | if(use_ns==1){ |
---|
1442 | ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
1443 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
1444 | ns_xsi=usedNs[xsiId]; |
---|
1445 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
1446 | ns_xlink=usedNs[xlinkId]; |
---|
1447 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"); |
---|
1448 | } |
---|
1449 | addLangAttr(n,m); |
---|
1450 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); |
---|
1451 | |
---|
1452 | nc = xmlNewNode(ns, BAD_CAST "Exception"); |
---|
1453 | |
---|
1454 | map* tmp=getMap(s,"code"); |
---|
1455 | if(tmp!=NULL) |
---|
1456 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); |
---|
1457 | else |
---|
1458 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); |
---|
1459 | |
---|
1460 | tmp=getMap(s,"text"); |
---|
1461 | nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); |
---|
1462 | nc2=NULL; |
---|
1463 | if(tmp!=NULL){ |
---|
1464 | xmlNodeSetContent(nc1, BAD_CAST tmp->value); |
---|
1465 | } |
---|
1466 | else{ |
---|
1467 | xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); |
---|
1468 | } |
---|
1469 | xmlAddChild(nc,nc1); |
---|
1470 | xmlAddChild(n,nc); |
---|
1471 | return n; |
---|
1472 | } |
---|
1473 | |
---|
1474 | |
---|
1475 | void outputResponse(service* s,maps* request_inputs,maps* request_outputs, |
---|
1476 | map* request_inputs1,int cpid,maps* m,int res){ |
---|
1477 | #ifdef DEBUG |
---|
1478 | dumpMaps(request_inputs); |
---|
1479 | dumpMaps(request_outputs); |
---|
1480 | fprintf(stderr,"printProcessResponse\n"); |
---|
1481 | #endif |
---|
1482 | map* toto=getMap(request_inputs1,"RawDataOutput"); |
---|
1483 | int asRaw=0; |
---|
1484 | if(toto!=NULL) |
---|
1485 | asRaw=1; |
---|
1486 | |
---|
1487 | if(asRaw==0){ |
---|
1488 | #ifdef DEBUG |
---|
1489 | fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); |
---|
1490 | dumpMaps(request_outputs); |
---|
1491 | #endif |
---|
1492 | toto=getMap(request_outputs->content,"asReference"); |
---|
1493 | if(toto!=NULL && strcasecmp(toto->value,"true")==0){ |
---|
1494 | toto=getMap(request_outputs->content,"extension"); |
---|
1495 | /* put gml extension if the extension is defined as .js and the result will be a gml file */ |
---|
1496 | map* mtype=getMap(request_outputs->content,"mimeType"); |
---|
1497 | if (strcasecmp(toto->value,"js")==0 && strcasecmp(mtype->value,"text/xml")==0) { |
---|
1498 | toto->value="gml"; |
---|
1499 | } |
---|
1500 | map *tmp1=getMapFromMaps(m,"main","tmpPath"); |
---|
1501 | char *file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char)); |
---|
1502 | sprintf(file_name,"%s/%s_%i.%s",tmp1->value,s->name,cpid+100000,toto->value); |
---|
1503 | FILE *ofile=fopen(file_name,"w"); |
---|
1504 | map *tmp2=getMapFromMaps(m,"main","tmpUrl"); |
---|
1505 | map *tmp3=getMapFromMaps(m,"main","serverAddress"); |
---|
1506 | char *file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char)); |
---|
1507 | sprintf(file_url,"%s/%s/%s_%i.%s",tmp3->value,tmp2->value,s->name,cpid+100000,toto->value); |
---|
1508 | addToMap(request_outputs->content,"Reference",file_url); |
---|
1509 | toto=getMap(request_outputs->content,"value"); |
---|
1510 | if(toto!=NULL) |
---|
1511 | fwrite(toto->value,sizeof(char),strlen(toto->value),ofile); |
---|
1512 | fclose(ofile); |
---|
1513 | free(file_name); |
---|
1514 | free(file_url); |
---|
1515 | } |
---|
1516 | map *r_inputs=getMap(s->content,"serviceProvider"); |
---|
1517 | #ifdef DEBUG |
---|
1518 | fprintf(stderr,"SERVICE : %s\n",r_inputs->value); |
---|
1519 | dumpMaps(m); |
---|
1520 | #endif |
---|
1521 | printProcessResponse(m,request_inputs1,cpid, |
---|
1522 | s,r_inputs->value,res, |
---|
1523 | request_inputs, |
---|
1524 | request_outputs); |
---|
1525 | } |
---|
1526 | else |
---|
1527 | if(res!=SERVICE_FAILED){ |
---|
1528 | /** |
---|
1529 | * We get the first output only !! |
---|
1530 | */ |
---|
1531 | toto=getMap(request_outputs->content,"value"); |
---|
1532 | if(toto==NULL){ |
---|
1533 | map * errormap = createMap("text",_("Unable to fetch any result")); |
---|
1534 | addToMap(errormap,"code", "InternalError"); |
---|
1535 | printExceptionReportResponse(m,errormap); |
---|
1536 | freeMap(&errormap); |
---|
1537 | free(errormap); |
---|
1538 | } |
---|
1539 | char mime[1024]; |
---|
1540 | map* mi=getMap(request_outputs->content,"mimeType"); |
---|
1541 | #ifdef DEBUG |
---|
1542 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
1543 | dumpMaps(request_outputs); |
---|
1544 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
1545 | #endif |
---|
1546 | map* en=getMap(request_outputs->content,"encoding"); |
---|
1547 | if(mi!=NULL && en!=NULL) |
---|
1548 | sprintf(mime, |
---|
1549 | "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", |
---|
1550 | mi->value,en->value); |
---|
1551 | else |
---|
1552 | if(mi!=NULL) |
---|
1553 | sprintf(mime, |
---|
1554 | "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", |
---|
1555 | mi->value); |
---|
1556 | else |
---|
1557 | sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); |
---|
1558 | printf("%s",mime); |
---|
1559 | if(mi!=NULL && strncmp(mi->value,"image",5)==0){ |
---|
1560 | map* rs=getMapFromMaps(request_outputs,request_outputs->name,"size"); |
---|
1561 | fwrite(toto->value,atoi(rs->value),1,stdout); |
---|
1562 | } |
---|
1563 | else |
---|
1564 | printf("%s",toto->value); |
---|
1565 | #ifdef DEBUG |
---|
1566 | dumpMap(toto); |
---|
1567 | #endif |
---|
1568 | }else{ |
---|
1569 | char tmp[1024]; |
---|
1570 | map * errormap; |
---|
1571 | map *lenv; |
---|
1572 | lenv=getMapFromMaps(m,"lenv","message"); |
---|
1573 | if(lenv!=NULL) |
---|
1574 | sprintf(tmp,_("Unable to run the Service. The message returned back by the Service was the following : %s"),lenv->value); |
---|
1575 | else |
---|
1576 | sprintf(tmp,_("Unable to run the Service. No more information was returned back by the Service.")); |
---|
1577 | errormap = createMap("text",tmp); |
---|
1578 | addToMap(errormap,"code", "InternalError"); |
---|
1579 | printExceptionReportResponse(m,errormap); |
---|
1580 | freeMap(&errormap); |
---|
1581 | free(errormap); |
---|
1582 | } |
---|
1583 | } |
---|
1584 | |
---|
1585 | char *base64(const unsigned char *input, int length) |
---|
1586 | { |
---|
1587 | BIO *bmem, *b64; |
---|
1588 | BUF_MEM *bptr; |
---|
1589 | |
---|
1590 | b64 = BIO_new(BIO_f_base64()); |
---|
1591 | bmem = BIO_new(BIO_s_mem()); |
---|
1592 | b64 = BIO_push(b64, bmem); |
---|
1593 | BIO_write(b64, input, length); |
---|
1594 | BIO_flush(b64); |
---|
1595 | BIO_get_mem_ptr(b64, &bptr); |
---|
1596 | |
---|
1597 | char *buff = (char *)malloc(bptr->length); |
---|
1598 | memcpy(buff, bptr->data, bptr->length-1); |
---|
1599 | buff[bptr->length-1] = 0; |
---|
1600 | |
---|
1601 | BIO_free_all(b64); |
---|
1602 | |
---|
1603 | fprintf(stderr,"BASE64 [%s] \n",buff); |
---|
1604 | return buff; |
---|
1605 | } |
---|
1606 | |
---|
1607 | char* addDefaultValues(maps** out,elements* in,maps* m,char* type){ |
---|
1608 | elements* tmpInputs=in; |
---|
1609 | maps* out1=*out; |
---|
1610 | while(tmpInputs!=NULL){ |
---|
1611 | maps *tmpMaps=getMaps(out1,tmpInputs->name); |
---|
1612 | if(tmpMaps==NULL){ |
---|
1613 | map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); |
---|
1614 | if(strncmp(type,"inputs",6)==0) |
---|
1615 | if(tmpMap1!=NULL && atoi(tmpMap1->value)>=1){ |
---|
1616 | return tmpInputs->name; |
---|
1617 | } |
---|
1618 | maps* tmpMaps2=(maps*)malloc(MAPS_SIZE); |
---|
1619 | tmpMaps2->name=strdup((char*)tmpInputs->name); |
---|
1620 | tmpMaps2->content=NULL; |
---|
1621 | tmpMaps2->next=NULL; |
---|
1622 | iotype* tmpIoType=tmpInputs->defaults; |
---|
1623 | while(tmpIoType!=NULL){ |
---|
1624 | addMapToMap(&tmpMaps2->content,tmpIoType->content); |
---|
1625 | tmpIoType=tmpIoType->next; |
---|
1626 | } |
---|
1627 | map *tmpMap=getMap(tmpMaps2->content,"value"); |
---|
1628 | if(tmpMap==NULL) |
---|
1629 | addToMap(tmpMaps2->content,"value","NULL"); |
---|
1630 | if(out1==NULL){ |
---|
1631 | *out=dupMaps(&tmpMaps2); |
---|
1632 | } |
---|
1633 | else |
---|
1634 | addMapsToMaps(&out1,tmpMaps2); |
---|
1635 | freeMaps(&tmpMaps2); |
---|
1636 | free(tmpMaps2); |
---|
1637 | tmpMaps2=NULL; |
---|
1638 | } |
---|
1639 | else{ |
---|
1640 | map* tmpContent=tmpInputs->defaults->content; |
---|
1641 | |
---|
1642 | map* cval=NULL; |
---|
1643 | |
---|
1644 | while(tmpContent!=NULL){ |
---|
1645 | if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){ |
---|
1646 | #ifdef DEBUG |
---|
1647 | fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value); |
---|
1648 | #endif |
---|
1649 | if(tmpMaps->content==NULL) |
---|
1650 | tmpMaps->content=createMap(tmpContent->name,tmpContent->value); |
---|
1651 | else |
---|
1652 | addToMap(tmpMaps->content,tmpContent->name,tmpContent->value); |
---|
1653 | } |
---|
1654 | tmpContent=tmpContent->next; |
---|
1655 | } |
---|
1656 | } |
---|
1657 | tmpInputs=tmpInputs->next; |
---|
1658 | } |
---|
1659 | return ""; |
---|
1660 | } |
---|