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(strcasecmp(tmp2->name,"abstract")==0 || |
---|
312 | strcasecmp(tmp2->name,"title")==0 || |
---|
313 | strcasecmp(tmp2->name,"accessConstraints")==0 || |
---|
314 | strcasecmp(tmp2->name,"fess")==0){ |
---|
315 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
316 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
317 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
318 | xmlAddChild(nc,nc1); |
---|
319 | } |
---|
320 | else |
---|
321 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
322 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
323 | char *toto=tmp2->value; |
---|
324 | char buff[256]; |
---|
325 | int i=0; |
---|
326 | int j=0; |
---|
327 | while(toto[i]){ |
---|
328 | if(toto[i]!=',' && toto[i]!=0){ |
---|
329 | buff[j]=toto[i]; |
---|
330 | buff[j+1]=0; |
---|
331 | j++; |
---|
332 | } |
---|
333 | else{ |
---|
334 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
335 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
336 | xmlAddChild(nc1,nc2); |
---|
337 | j=0; |
---|
338 | } |
---|
339 | i++; |
---|
340 | } |
---|
341 | if(strlen(buff)>0){ |
---|
342 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
343 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
344 | xmlAddChild(nc1,nc2); |
---|
345 | } |
---|
346 | xmlAddChild(nc,nc1); |
---|
347 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); |
---|
348 | xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); |
---|
349 | xmlAddChild(nc,nc2); |
---|
350 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); |
---|
351 | xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); |
---|
352 | xmlAddChild(nc,nc2); |
---|
353 | } |
---|
354 | tmp2=tmp2->next; |
---|
355 | } |
---|
356 | } |
---|
357 | else{ |
---|
358 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
359 | return NULL; |
---|
360 | } |
---|
361 | xmlAddChild(n,nc); |
---|
362 | |
---|
363 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); |
---|
364 | nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); |
---|
365 | nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); |
---|
366 | nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); |
---|
367 | nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); |
---|
368 | tmp4=getMaps(m,"provider"); |
---|
369 | if(tmp4!=NULL){ |
---|
370 | map* tmp2=tmp4->content; |
---|
371 | char *tmpAddress[6]; |
---|
372 | tmpAddress[0]="addressDeliveryPoint"; |
---|
373 | tmpAddress[1]="addressCity"; |
---|
374 | tmpAddress[2]="addressAdministrativeArea"; |
---|
375 | tmpAddress[3]="addressPostalCode"; |
---|
376 | tmpAddress[4]="addressCountry"; |
---|
377 | tmpAddress[5]="addressElectronicMailAddress"; |
---|
378 | char *tmpPhone[2]; |
---|
379 | tmpPhone[0]="phoneVoice"; |
---|
380 | tmpPhone[1]="phoneFacsimile"; |
---|
381 | while(tmp2!=NULL){ |
---|
382 | if(strcmp(tmp2->name,"keywords")!=0 && |
---|
383 | strcmp(tmp2->name,"serverAddress")!=0 && |
---|
384 | strcmp(tmp2->name,"lang")!=0){ |
---|
385 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
386 | if(strcmp(tmp2->name,"ProviderName")==0){ |
---|
387 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
388 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
389 | xmlAddChild(nc,nc1); |
---|
390 | } |
---|
391 | else{ |
---|
392 | if(strcmp(tmp2->name,"ProviderSite")==0){ |
---|
393 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
394 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); |
---|
395 | xmlAddChild(nc,nc1); |
---|
396 | } |
---|
397 | else |
---|
398 | if(strcmp(tmp2->name,"IndividualName")==0 || |
---|
399 | strcmp(tmp2->name,"PositionName")==0){ |
---|
400 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
401 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
402 | xmlAddChild(nc3,nc1); |
---|
403 | } |
---|
404 | else |
---|
405 | if(strncmp(tmp2->name,"Phone",5)==0){ |
---|
406 | int j; |
---|
407 | for(j=0;j<2;j++) |
---|
408 | if(strcasecmp(tmp2->name,tmpPhone[j])==0){ |
---|
409 | char *toto=NULL; |
---|
410 | char *toto1=tmp2->name; |
---|
411 | toto=strstr(toto1,"Phone"); |
---|
412 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5); |
---|
413 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
414 | xmlAddChild(nc5,nc1); |
---|
415 | } |
---|
416 | } |
---|
417 | else |
---|
418 | if(strncmp(tmp2->name,"Address",7)==0){ |
---|
419 | int j; |
---|
420 | for(j=0;j<6;j++) |
---|
421 | if(strcasecmp(tmp2->name,tmpAddress[j])==0){ |
---|
422 | char *toto=NULL; |
---|
423 | char *toto1=tmp2->name; |
---|
424 | toto=strstr(toto1,"Address"); |
---|
425 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7); |
---|
426 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
427 | xmlAddChild(nc6,nc1); |
---|
428 | } |
---|
429 | } |
---|
430 | } |
---|
431 | } |
---|
432 | else |
---|
433 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
434 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
435 | char *toto=tmp2->value; |
---|
436 | char buff[256]; |
---|
437 | int i=0; |
---|
438 | int j=0; |
---|
439 | while(toto[i]){ |
---|
440 | if(toto[i]!=',' && toto[i]!=0){ |
---|
441 | buff[j]=toto[i]; |
---|
442 | buff[j+1]=0; |
---|
443 | j++; |
---|
444 | } |
---|
445 | else{ |
---|
446 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
447 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
448 | xmlAddChild(nc1,nc2); |
---|
449 | j=0; |
---|
450 | } |
---|
451 | i++; |
---|
452 | } |
---|
453 | if(strlen(buff)>0){ |
---|
454 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
455 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
456 | xmlAddChild(nc1,nc2); |
---|
457 | } |
---|
458 | xmlAddChild(nc,nc1); |
---|
459 | } |
---|
460 | tmp2=tmp2->next; |
---|
461 | } |
---|
462 | } |
---|
463 | else{ |
---|
464 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
465 | } |
---|
466 | xmlAddChild(nc4,nc5); |
---|
467 | xmlAddChild(nc4,nc6); |
---|
468 | xmlAddChild(nc3,nc4); |
---|
469 | xmlAddChild(nc,nc3); |
---|
470 | xmlAddChild(n,nc); |
---|
471 | |
---|
472 | |
---|
473 | nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); |
---|
474 | char *tmp2[3]; |
---|
475 | tmp2[0]=strdup("GetCapabilities"); |
---|
476 | tmp2[1]=strdup("DescribeProcess"); |
---|
477 | tmp2[2]=strdup("Execute"); |
---|
478 | int j=0; |
---|
479 | |
---|
480 | if(toto1!=NULL){ |
---|
481 | map* tmp=getMap(toto1->content,"serverAddress"); |
---|
482 | if(tmp!=NULL){ |
---|
483 | SERVICE_URL = strdup(tmp->value); |
---|
484 | } |
---|
485 | else |
---|
486 | SERVICE_URL = strdup("not_found"); |
---|
487 | } |
---|
488 | else |
---|
489 | SERVICE_URL = strdup("not_found"); |
---|
490 | |
---|
491 | for(j=0;j<3;j++){ |
---|
492 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); |
---|
493 | xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]); |
---|
494 | nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); |
---|
495 | nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); |
---|
496 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); |
---|
497 | sprintf(tmp,"%s/%s",SERVICE_URL,service); |
---|
498 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
499 | xmlAddChild(nc3,nc4); |
---|
500 | if(j>0){ |
---|
501 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); |
---|
502 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
503 | xmlAddChild(nc3,nc4); |
---|
504 | } |
---|
505 | xmlAddChild(nc2,nc3); |
---|
506 | xmlAddChild(nc1,nc2); |
---|
507 | xmlAddChild(nc,nc1); |
---|
508 | } |
---|
509 | for(j=2;j>=0;j--) |
---|
510 | free(tmp2[j]); |
---|
511 | xmlAddChild(n,nc); |
---|
512 | |
---|
513 | nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); |
---|
514 | xmlAddChild(n,nc); |
---|
515 | |
---|
516 | nc1 = xmlNewNode(ns, BAD_CAST "Languages"); |
---|
517 | nc2 = xmlNewNode(ns, BAD_CAST "Default"); |
---|
518 | nc3 = xmlNewNode(ns, BAD_CAST "Supported"); |
---|
519 | |
---|
520 | toto1=getMaps(m,"main"); |
---|
521 | if(toto1!=NULL){ |
---|
522 | map* tmp1=getMap(toto1->content,"lang"); |
---|
523 | char *toto=tmp1->value; |
---|
524 | char buff[256]; |
---|
525 | int i=0; |
---|
526 | int j=0; |
---|
527 | int dcount=0; |
---|
528 | while(toto[i]){ |
---|
529 | if(toto[i]!=',' && toto[i]!=0){ |
---|
530 | buff[j]=toto[i]; |
---|
531 | buff[j+1]=0; |
---|
532 | j++; |
---|
533 | } |
---|
534 | else{ |
---|
535 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
536 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
537 | if(dcount==0){ |
---|
538 | xmlAddChild(nc2,nc4); |
---|
539 | xmlAddChild(nc1,nc2); |
---|
540 | dcount++; |
---|
541 | } |
---|
542 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
543 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
544 | xmlAddChild(nc3,nc4); |
---|
545 | j=0; |
---|
546 | buff[j]=0; |
---|
547 | } |
---|
548 | i++; |
---|
549 | } |
---|
550 | if(strlen(buff)>0){ |
---|
551 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
552 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
553 | xmlAddChild(nc3,nc4); |
---|
554 | } |
---|
555 | } |
---|
556 | xmlAddChild(nc1,nc3); |
---|
557 | xmlAddChild(n,nc1); |
---|
558 | |
---|
559 | xmlDocSetRootElement(doc, n); |
---|
560 | //xmlFreeNs(ns); |
---|
561 | free(SERVICE_URL); |
---|
562 | return nc; |
---|
563 | } |
---|
564 | |
---|
565 | void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ |
---|
566 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
567 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
568 | /** |
---|
569 | * Initialize or get existing namspaces |
---|
570 | */ |
---|
571 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
572 | ns=usedNs[wpsId]; |
---|
573 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
574 | ns_ows=usedNs[owsId]; |
---|
575 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
576 | ns_xlink=usedNs[xlinkId]; |
---|
577 | |
---|
578 | int cursor=0; |
---|
579 | map* tmp1; |
---|
580 | if(serv->content!=NULL){ |
---|
581 | nc1 = xmlNewNode(ns, BAD_CAST "Process"); |
---|
582 | tmp1=getMap(serv->content,"processVersion"); |
---|
583 | if(tmp1!=NULL) |
---|
584 | xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
585 | printDescription(nc1,ns_ows,serv->name,serv->content); |
---|
586 | tmp1=serv->metadata; |
---|
587 | while(tmp1!=NULL){ |
---|
588 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
589 | xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
590 | xmlAddChild(nc1,nc2); |
---|
591 | tmp1=tmp1->next; |
---|
592 | } |
---|
593 | xmlAddChild(nc,nc1); |
---|
594 | } |
---|
595 | } |
---|
596 | |
---|
597 | xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){ |
---|
598 | |
---|
599 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
600 | xmlNodePtr n,nr; |
---|
601 | xmlChar *xmlbuff; |
---|
602 | int buffersize; |
---|
603 | |
---|
604 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
605 | ns=usedNs[wpsId]; |
---|
606 | n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions"); |
---|
607 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
608 | ns_ows=usedNs[owsId]; |
---|
609 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
610 | zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
611 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
612 | ns_xsi=usedNs[xsiId]; |
---|
613 | |
---|
614 | 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"); |
---|
615 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
616 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
617 | addLangAttr(n,m); |
---|
618 | |
---|
619 | xmlDocSetRootElement(doc, n); |
---|
620 | |
---|
621 | return n; |
---|
622 | } |
---|
623 | |
---|
624 | void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){ |
---|
625 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
626 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
627 | |
---|
628 | char tmp[256]; |
---|
629 | n=nc; |
---|
630 | |
---|
631 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
632 | ns=usedNs[wpsId]; |
---|
633 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
634 | ns_ows=usedNs[owsId]; |
---|
635 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
636 | ns_xlink=usedNs[xlinkId]; |
---|
637 | |
---|
638 | nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); |
---|
639 | char *tmp4[3]; |
---|
640 | tmp4[0]="processVersion"; |
---|
641 | tmp4[1]="storeSupported"; |
---|
642 | tmp4[2]="statusSupported"; |
---|
643 | int j=0; |
---|
644 | map* tmp1=NULL; |
---|
645 | for(j=0;j<3;j++){ |
---|
646 | tmp1=getMap(serv->content,tmp4[j]); |
---|
647 | if(tmp1!=NULL){ |
---|
648 | if(j==0) |
---|
649 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
650 | else |
---|
651 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value); |
---|
652 | } |
---|
653 | else{ |
---|
654 | if(j>0) |
---|
655 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); |
---|
656 | } |
---|
657 | } |
---|
658 | |
---|
659 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
660 | |
---|
661 | tmp1=serv->metadata; |
---|
662 | while(tmp1!=NULL){ |
---|
663 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
664 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
665 | xmlAddChild(nc,nc1); |
---|
666 | tmp1=tmp1->next; |
---|
667 | } |
---|
668 | |
---|
669 | tmp1=getMap(serv->content,"Profile"); |
---|
670 | if(tmp1!=NULL){ |
---|
671 | nc1 = xmlNewNode(ns, BAD_CAST "Profile"); |
---|
672 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); |
---|
673 | xmlAddChild(nc,nc1); |
---|
674 | } |
---|
675 | |
---|
676 | nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); |
---|
677 | |
---|
678 | elements* e=serv->inputs; |
---|
679 | while(e!=NULL){ |
---|
680 | nc2 = xmlNewNode(NULL, BAD_CAST "Input"); |
---|
681 | tmp1=getMap(e->content,"minOccurs"); |
---|
682 | if(tmp1){ |
---|
683 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
684 | } |
---|
685 | tmp1=getMap(e->content,"maxOccurs"); |
---|
686 | if(tmp1){ |
---|
687 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
688 | } |
---|
689 | |
---|
690 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
691 | |
---|
692 | |
---|
693 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
694 | iotype* _tmp=e->defaults; |
---|
695 | int datatype=0; |
---|
696 | if(_tmp!=NULL){ |
---|
697 | int isAnyValue=1; |
---|
698 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
699 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
700 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
701 | } |
---|
702 | else{ |
---|
703 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
704 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
705 | datatype=1; |
---|
706 | } |
---|
707 | tmp1=_tmp->content; |
---|
708 | int default1=0; |
---|
709 | xmlNodePtr nc7; |
---|
710 | while(tmp1!=NULL){ |
---|
711 | #ifdef DEBUG |
---|
712 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
713 | #endif |
---|
714 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
715 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
716 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
717 | char tmp[1024]; |
---|
718 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
719 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
720 | xmlAddChild(nc3,nc6); |
---|
721 | tmp1=tmp1->next; |
---|
722 | continue; |
---|
723 | } |
---|
724 | if(strcasecmp(tmp1->name,"asReference")!=0 && |
---|
725 | strcasecmp(tmp1->name,"DataType")!=0 && |
---|
726 | strncasecmp(tmp1->name,"AllowedValues",13)!=0 && |
---|
727 | strcasecmp(tmp1->name,"value")!=0 && |
---|
728 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
729 | if(datatype==0){ |
---|
730 | char *tmp2=zCapitalize1(tmp1->name); |
---|
731 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
732 | free(tmp2); |
---|
733 | } |
---|
734 | else{ |
---|
735 | char *tmp2=zCapitalize(tmp1->name); |
---|
736 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
737 | free(tmp2); |
---|
738 | } |
---|
739 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
740 | xmlAddChild(nc5,nc6); |
---|
741 | } |
---|
742 | else{ |
---|
743 | if(strcmp(tmp1->name,"value")==0){ |
---|
744 | nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); |
---|
745 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
746 | default1=1; |
---|
747 | } |
---|
748 | if(strncasecmp(tmp1->name,"AllowedValues",13)==0){ |
---|
749 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
750 | char *token,*saveptr1; |
---|
751 | token=strtok_r(tmp1->value,",",&saveptr1); |
---|
752 | while(token!=NULL){ |
---|
753 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
754 | char *tmps=strdup(token); |
---|
755 | tmps[strlen(tmps)]=0; |
---|
756 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); |
---|
757 | fprintf(stderr,"strgin : %s\n",tmps); |
---|
758 | xmlAddChild(nc6,nc7); |
---|
759 | token=strtok_r(NULL,",",&saveptr1); |
---|
760 | } |
---|
761 | xmlAddChild(nc3,nc6); |
---|
762 | isAnyValue=-1; |
---|
763 | } |
---|
764 | } |
---|
765 | tmp1=tmp1->next; |
---|
766 | } |
---|
767 | xmlAddChild(nc4,nc5); |
---|
768 | xmlAddChild(nc3,nc4); |
---|
769 | if(datatype==1 && isAnyValue==1){ |
---|
770 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
771 | if(default1>0) |
---|
772 | xmlAddChild(nc3,nc7); |
---|
773 | } |
---|
774 | if(datatype==1 && default1>0) |
---|
775 | xmlAddChild(nc3,nc7); |
---|
776 | } |
---|
777 | xmlAddChild(nc2,nc3); |
---|
778 | |
---|
779 | _tmp=e->supported; |
---|
780 | while(_tmp!=NULL){ |
---|
781 | if(datatype==0){ |
---|
782 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
783 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
784 | } |
---|
785 | else{ |
---|
786 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
787 | } |
---|
788 | tmp1=_tmp->content; |
---|
789 | while(tmp1!=NULL){ |
---|
790 | /*if(strcmp(e->format,"LiteralData")==0) |
---|
791 | xmlAddChild(nc5,nc6);*/ |
---|
792 | if(datatype==0){ |
---|
793 | char *tmp2=zCapitalize1(tmp1->name); |
---|
794 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
795 | free(tmp2); |
---|
796 | } |
---|
797 | else{ |
---|
798 | char *tmp2=zCapitalize(tmp1->name); |
---|
799 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
800 | free(tmp2); |
---|
801 | } |
---|
802 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
803 | xmlAddChild(nc5,nc6); |
---|
804 | tmp1=tmp1->next; |
---|
805 | } |
---|
806 | if(datatype==0){ |
---|
807 | xmlAddChild(nc4,nc5); |
---|
808 | xmlAddChild(nc3,nc4); |
---|
809 | }else{ |
---|
810 | xmlAddChild(nc4,nc5); |
---|
811 | } |
---|
812 | _tmp=_tmp->next; |
---|
813 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
814 | xmlAddChild(nc2,nc3); |
---|
815 | } |
---|
816 | } |
---|
817 | xmlAddChild(nc1,nc2); |
---|
818 | |
---|
819 | |
---|
820 | e=e->next; |
---|
821 | } |
---|
822 | xmlAddChild(nc,nc1); |
---|
823 | |
---|
824 | nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); |
---|
825 | |
---|
826 | e=serv->outputs; |
---|
827 | while(e!=NULL){ |
---|
828 | nc2 = xmlNewNode(NULL, BAD_CAST "Output"); |
---|
829 | tmp1=getMap(e->content,"minOccurs"); |
---|
830 | if(tmp1){ |
---|
831 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
832 | } |
---|
833 | tmp1=getMap(e->content,"maxOccurs"); |
---|
834 | if(tmp1){ |
---|
835 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
836 | } |
---|
837 | |
---|
838 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
839 | |
---|
840 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) |
---|
841 | nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput"); |
---|
842 | else |
---|
843 | if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
844 | nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput"); |
---|
845 | else |
---|
846 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
847 | iotype* _tmp=e->defaults; |
---|
848 | int datatype=0; |
---|
849 | if(_tmp!=NULL){ |
---|
850 | if(strcmp(e->format,"LiteralOutput")==0 || |
---|
851 | strcmp(e->format,"LiteralData")==0){ |
---|
852 | datatype=1; |
---|
853 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
854 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
855 | } |
---|
856 | else{ |
---|
857 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
858 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
859 | } |
---|
860 | tmp1=_tmp->content; |
---|
861 | while(tmp1!=NULL){ |
---|
862 | #ifdef DEBUG |
---|
863 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
864 | #endif |
---|
865 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
866 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
867 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
868 | char tmp[1024]; |
---|
869 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
870 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
871 | xmlAddChild(nc3,nc6); |
---|
872 | tmp1=tmp1->next; |
---|
873 | datatype=1; |
---|
874 | continue; |
---|
875 | } |
---|
876 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
877 | strncasecmp(tmp1->name,"DataType",8)!=0 && |
---|
878 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
879 | if(datatype==0){ |
---|
880 | char *tmp2=zCapitalize1(tmp1->name); |
---|
881 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
882 | free(tmp2); |
---|
883 | } |
---|
884 | else{ |
---|
885 | char *tmp2=zCapitalize(tmp1->name); |
---|
886 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
887 | free(tmp2); |
---|
888 | } |
---|
889 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
890 | xmlAddChild(nc5,nc6); |
---|
891 | } |
---|
892 | tmp1=tmp1->next; |
---|
893 | } |
---|
894 | xmlAddChild(nc4,nc5); |
---|
895 | xmlAddChild(nc3,nc4); |
---|
896 | } |
---|
897 | _tmp=e->supported; |
---|
898 | while(_tmp!=NULL){ |
---|
899 | if(datatype==0){ |
---|
900 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
901 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
902 | } |
---|
903 | else |
---|
904 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
905 | tmp1=_tmp->content; |
---|
906 | while(tmp1!=NULL){ |
---|
907 | #ifdef DEBUG |
---|
908 | printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); |
---|
909 | #endif |
---|
910 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
911 | strcmp(tmp1->name,"DataType")!=0 && |
---|
912 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
913 | if(datatype==0){ |
---|
914 | char *tmp2=zCapitalize1(tmp1->name); |
---|
915 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
916 | free(tmp2); |
---|
917 | } |
---|
918 | else{ |
---|
919 | char *tmp2=zCapitalize(tmp1->name); |
---|
920 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
921 | free(tmp2); |
---|
922 | } |
---|
923 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
924 | xmlAddChild(nc5,nc6); |
---|
925 | } |
---|
926 | tmp1=tmp1->next; |
---|
927 | } |
---|
928 | _tmp=_tmp->next; |
---|
929 | if(datatype==0){ |
---|
930 | xmlAddChild(nc4,nc5); |
---|
931 | xmlAddChild(nc3,nc4); |
---|
932 | }else |
---|
933 | xmlAddChild(nc4,nc5); |
---|
934 | } |
---|
935 | xmlAddChild(nc2,nc3); |
---|
936 | |
---|
937 | xmlAddChild(nc3,nc4); |
---|
938 | |
---|
939 | |
---|
940 | xmlAddChild(nc2,nc3); |
---|
941 | |
---|
942 | xmlAddChild(nc1,nc2); |
---|
943 | |
---|
944 | e=e->next; |
---|
945 | } |
---|
946 | xmlAddChild(nc,nc1); |
---|
947 | |
---|
948 | xmlAddChild(n,nc); |
---|
949 | |
---|
950 | } |
---|
951 | |
---|
952 | void printProcessResponse(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){ |
---|
953 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
954 | xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor; |
---|
955 | xmlDocPtr doc; |
---|
956 | xmlChar *xmlbuff; |
---|
957 | int buffersize; |
---|
958 | time_t time1; |
---|
959 | time(&time1); |
---|
960 | /** |
---|
961 | * Create the document and its temporary root. |
---|
962 | */ |
---|
963 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
964 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
965 | ns=usedNs[wpsId]; |
---|
966 | |
---|
967 | n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); |
---|
968 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
969 | ns_ows=usedNs[owsId]; |
---|
970 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
971 | ns_xlink=usedNs[xlinkId]; |
---|
972 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
973 | ns_xsi=usedNs[xsiId]; |
---|
974 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
975 | |
---|
976 | 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"); |
---|
977 | |
---|
978 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
979 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
980 | addLangAttr(n,m); |
---|
981 | |
---|
982 | char tmp[256]; |
---|
983 | char url[1024]; |
---|
984 | memset(tmp,0,256); |
---|
985 | memset(url,0,256); |
---|
986 | maps* tmp_maps=getMaps(m,"main"); |
---|
987 | if(tmp_maps!=NULL){ |
---|
988 | map* tmpm1=getMap(tmp_maps->content,"serverAddress"); |
---|
989 | /** |
---|
990 | * Check if the ZOO Service GetStatus is available in the local directory. |
---|
991 | * If yes, then it uses a reference to an URL which the client can access |
---|
992 | * to get information on the status of a running Service (using the |
---|
993 | * percentCompleted attribute). |
---|
994 | * Else fallback to the initial method using the xml file to write in ... |
---|
995 | */ |
---|
996 | char ntmp[1024]; |
---|
997 | #ifndef WIN32 |
---|
998 | getcwd(ntmp,1024); |
---|
999 | #else |
---|
1000 | _getcwd(ntmp,1024); |
---|
1001 | #endif |
---|
1002 | struct stat myFileInfo; |
---|
1003 | int statRes; |
---|
1004 | char file_path[1024]; |
---|
1005 | sprintf(file_path,"%s/GetStatus.zcfg",ntmp); |
---|
1006 | statRes=stat(file_path,&myFileInfo); |
---|
1007 | if(statRes==0){ |
---|
1008 | char currentSid[128]; |
---|
1009 | map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); |
---|
1010 | map *tmp_lenv=NULL; |
---|
1011 | tmp_lenv=getMapFromMaps(m,"lenv","sid"); |
---|
1012 | if(tmp_lenv==NULL) |
---|
1013 | sprintf(currentSid,"%i",pid); |
---|
1014 | else |
---|
1015 | sprintf(currentSid,"%s",tmp_lenv->value); |
---|
1016 | if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ |
---|
1017 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1018 | }else{ |
---|
1019 | if(strlen(tmpm->value)>0) |
---|
1020 | if(strcasecmp(tmpm->value,"true")!=0) |
---|
1021 | sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); |
---|
1022 | else |
---|
1023 | sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); |
---|
1024 | else |
---|
1025 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
1026 | } |
---|
1027 | }else{ |
---|
1028 | map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); |
---|
1029 | if(tmpm1!=NULL && tmpm2!=NULL){ |
---|
1030 | sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); |
---|
1031 | } |
---|
1032 | } |
---|
1033 | if(tmpm1!=NULL) |
---|
1034 | sprintf(tmp,"%s/",tmpm1->value); |
---|
1035 | } |
---|
1036 | |
---|
1037 | xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); |
---|
1038 | if(status!=SERVICE_SUCCEEDED && status!=SERVICE_FAILED){ |
---|
1039 | xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); |
---|
1040 | } |
---|
1041 | |
---|
1042 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
1043 | map* tmp2=getMap(serv->content,"processVersion"); |
---|
1044 | |
---|
1045 | if(tmp2!=NULL) |
---|
1046 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); |
---|
1047 | |
---|
1048 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
1049 | fflush(stderr); |
---|
1050 | |
---|
1051 | xmlAddChild(n,nc); |
---|
1052 | |
---|
1053 | nc = xmlNewNode(ns, BAD_CAST "Status"); |
---|
1054 | const struct tm *tm; |
---|
1055 | size_t len; |
---|
1056 | time_t now; |
---|
1057 | char *tmp1; |
---|
1058 | map *tmpStatus; |
---|
1059 | |
---|
1060 | now = time ( NULL ); |
---|
1061 | tm = localtime ( &now ); |
---|
1062 | |
---|
1063 | tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); |
---|
1064 | |
---|
1065 | len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); |
---|
1066 | |
---|
1067 | xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); |
---|
1068 | |
---|
1069 | char sMsg[2048]; |
---|
1070 | switch(status){ |
---|
1071 | case SERVICE_SUCCEEDED: |
---|
1072 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); |
---|
1073 | sprintf(sMsg,_("Service \"%s\" run successfully."),serv->name); |
---|
1074 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1075 | xmlAddChild(nc1,nc3); |
---|
1076 | break; |
---|
1077 | case SERVICE_STARTED: |
---|
1078 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); |
---|
1079 | tmpStatus=getMapFromMaps(m,"lenv","status"); |
---|
1080 | xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); |
---|
1081 | sprintf(sMsg,_("ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service."),serv->name); |
---|
1082 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1083 | xmlAddChild(nc1,nc3); |
---|
1084 | break; |
---|
1085 | case SERVICE_ACCEPTED: |
---|
1086 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); |
---|
1087 | 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); |
---|
1088 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
1089 | xmlAddChild(nc1,nc3); |
---|
1090 | break; |
---|
1091 | case SERVICE_FAILED: |
---|
1092 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); |
---|
1093 | map *errorMap; |
---|
1094 | map *te; |
---|
1095 | te=getMapFromMaps(m,"lenv","code"); |
---|
1096 | if(te!=NULL) |
---|
1097 | errorMap=createMap("code",te->value); |
---|
1098 | else |
---|
1099 | errorMap=createMap("code","NoApplicableCode"); |
---|
1100 | te=getMapFromMaps(m,"lenv","message"); |
---|
1101 | if(te!=NULL) |
---|
1102 | addToMap(errorMap,"text",_ss(te->value)); |
---|
1103 | else |
---|
1104 | addToMap(errorMap,"text",_("No more information available")); |
---|
1105 | nc3=createExceptionReportNode(m,errorMap,0); |
---|
1106 | freeMap(&errorMap); |
---|
1107 | free(errorMap); |
---|
1108 | xmlAddChild(nc1,nc3); |
---|
1109 | break; |
---|
1110 | default : |
---|
1111 | printf(_("error code not know : %i\n"),status); |
---|
1112 | //exit(1); |
---|
1113 | break; |
---|
1114 | } |
---|
1115 | xmlAddChild(nc,nc1); |
---|
1116 | xmlAddChild(n,nc); |
---|
1117 | free(tmp1); |
---|
1118 | |
---|
1119 | #ifdef DEBUG |
---|
1120 | fprintf(stderr,"printProcessResponse 1 161\n"); |
---|
1121 | #endif |
---|
1122 | |
---|
1123 | map* lineage=getMap(request,"lineage"); |
---|
1124 | if(lineage!=NULL){ |
---|
1125 | nc = xmlNewNode(ns, BAD_CAST "DataInputs"); |
---|
1126 | int i; |
---|
1127 | maps* mcursor=inputs; |
---|
1128 | elements* scursor=NULL; |
---|
1129 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
1130 | scursor=getElements(serv->inputs,mcursor->name); |
---|
1131 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Input"); |
---|
1132 | mcursor=mcursor->next; |
---|
1133 | } |
---|
1134 | xmlAddChild(n,nc); |
---|
1135 | |
---|
1136 | #ifdef DEBUG |
---|
1137 | fprintf(stderr,"printProcessResponse 1 177\n"); |
---|
1138 | #endif |
---|
1139 | |
---|
1140 | nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); |
---|
1141 | mcursor=outputs; |
---|
1142 | scursor=NULL; |
---|
1143 | while(mcursor!=NULL){ |
---|
1144 | scursor=getElements(serv->outputs,mcursor->name); |
---|
1145 | printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
1146 | mcursor=mcursor->next; |
---|
1147 | } |
---|
1148 | xmlAddChild(n,nc); |
---|
1149 | } |
---|
1150 | #ifdef DEBUG |
---|
1151 | fprintf(stderr,"printProcessResponse 1 190\n"); |
---|
1152 | #endif |
---|
1153 | |
---|
1154 | /** |
---|
1155 | * Display the process output only when requested ! |
---|
1156 | */ |
---|
1157 | if(status==SERVICE_SUCCEEDED){ |
---|
1158 | nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); |
---|
1159 | maps* mcursor=outputs; |
---|
1160 | elements* scursor=serv->outputs; |
---|
1161 | while(mcursor!=NULL){ |
---|
1162 | scursor=getElements(serv->outputs,mcursor->name); |
---|
1163 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
1164 | mcursor=mcursor->next; |
---|
1165 | } |
---|
1166 | xmlAddChild(n,nc); |
---|
1167 | } |
---|
1168 | #ifdef DEBUG |
---|
1169 | fprintf(stderr,"printProcessResponse 1 202\n"); |
---|
1170 | #endif |
---|
1171 | xmlDocSetRootElement(doc, n); |
---|
1172 | printDocument(m,doc,pid); |
---|
1173 | |
---|
1174 | xmlCleanupParser(); |
---|
1175 | zooXmlCleanupNs(); |
---|
1176 | } |
---|
1177 | |
---|
1178 | |
---|
1179 | void printDocument(maps* m, xmlDocPtr doc,int pid){ |
---|
1180 | rewind(stdout); |
---|
1181 | char *encoding=getEncoding(m); |
---|
1182 | if(pid==getpid()){ |
---|
1183 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1184 | } |
---|
1185 | fflush(stdout); |
---|
1186 | xmlChar *xmlbuff; |
---|
1187 | int buffersize; |
---|
1188 | /* |
---|
1189 | * Dump the document to a buffer and print it on stdout |
---|
1190 | * for demonstration purposes. |
---|
1191 | */ |
---|
1192 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
1193 | printf((char *) xmlbuff); |
---|
1194 | //fflush(stdout); |
---|
1195 | /* |
---|
1196 | * Free associated memory. |
---|
1197 | */ |
---|
1198 | xmlFree(xmlbuff); |
---|
1199 | xmlFreeDoc(doc); |
---|
1200 | xmlCleanupParser(); |
---|
1201 | zooXmlCleanupNs(); |
---|
1202 | } |
---|
1203 | |
---|
1204 | void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
1205 | xmlNodePtr nc1; |
---|
1206 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1207 | map *tmp=NULL; |
---|
1208 | if(e!=NULL && e->defaults!=NULL) |
---|
1209 | tmp=e->defaults->content; |
---|
1210 | else{ |
---|
1211 | /* |
---|
1212 | dumpElements(e); |
---|
1213 | */ |
---|
1214 | return; |
---|
1215 | } |
---|
1216 | while(tmp!=NULL){ |
---|
1217 | if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 |
---|
1218 | || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 |
---|
1219 | || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 |
---|
1220 | || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) |
---|
1221 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1222 | tmp=tmp->next; |
---|
1223 | } |
---|
1224 | tmp=getMap(e->defaults->content,"asReference"); |
---|
1225 | if(tmp==NULL) |
---|
1226 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
1227 | |
---|
1228 | tmp=e->content; |
---|
1229 | |
---|
1230 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
1231 | |
---|
1232 | xmlAddChild(nc,nc1); |
---|
1233 | |
---|
1234 | } |
---|
1235 | |
---|
1236 | void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){ |
---|
1237 | xmlNodePtr nc1,nc2,nc3; |
---|
1238 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1239 | map *tmp=NULL; |
---|
1240 | if(e!=NULL && e->defaults!=NULL) |
---|
1241 | tmp=e->defaults->content; |
---|
1242 | else{ |
---|
1243 | /* |
---|
1244 | dumpElements(e); |
---|
1245 | */ |
---|
1246 | return; |
---|
1247 | } |
---|
1248 | while(tmp!=NULL){ |
---|
1249 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1250 | tmp=tmp->next; |
---|
1251 | } |
---|
1252 | tmp=getMap(e->defaults->content,"asReference"); |
---|
1253 | if(tmp==NULL) |
---|
1254 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
1255 | |
---|
1256 | tmp=e->content; |
---|
1257 | |
---|
1258 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
1259 | |
---|
1260 | xmlAddChild(nc,nc1); |
---|
1261 | |
---|
1262 | } |
---|
1263 | |
---|
1264 | void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
1265 | xmlNodePtr nc1,nc2,nc3; |
---|
1266 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
1267 | map *tmp=NULL; |
---|
1268 | if(e!=NULL) |
---|
1269 | tmp=e->content; |
---|
1270 | else |
---|
1271 | tmp=m->content; |
---|
1272 | #ifdef DEBUG |
---|
1273 | dumpMap(tmp); |
---|
1274 | dumpElements(e); |
---|
1275 | #endif |
---|
1276 | nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
1277 | if(e!=NULL) |
---|
1278 | nc3=xmlNewText(BAD_CAST e->name); |
---|
1279 | else |
---|
1280 | nc3=xmlNewText(BAD_CAST m->name); |
---|
1281 | xmlAddChild(nc2,nc3); |
---|
1282 | xmlAddChild(nc1,nc2); |
---|
1283 | xmlAddChild(nc,nc1); |
---|
1284 | // Extract Title required to be first element in the ZCFG file ! |
---|
1285 | bool isTitle=true; |
---|
1286 | if(e!=NULL) |
---|
1287 | tmp=getMap(e->content,"Title"); |
---|
1288 | else |
---|
1289 | tmp=getMap(m->content,"Title"); |
---|
1290 | |
---|
1291 | if(tmp!=NULL){ |
---|
1292 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1293 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1294 | xmlAddChild(nc2,nc3); |
---|
1295 | xmlAddChild(nc1,nc2); |
---|
1296 | } |
---|
1297 | |
---|
1298 | if(e!=NULL) |
---|
1299 | tmp=getMap(e->content,"Abstract"); |
---|
1300 | else |
---|
1301 | tmp=getMap(m->content,"Abstract"); |
---|
1302 | if(tmp!=NULL){ |
---|
1303 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
1304 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
1305 | xmlAddChild(nc2,nc3); |
---|
1306 | xmlAddChild(nc1,nc2); |
---|
1307 | xmlAddChild(nc,nc1); |
---|
1308 | } |
---|
1309 | |
---|
1310 | /** |
---|
1311 | * IO type Reference or full Data ? |
---|
1312 | */ |
---|
1313 | #ifdef DEBUG |
---|
1314 | fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); |
---|
1315 | #endif |
---|
1316 | map *tmpMap=getMap(m->content,"Reference"); |
---|
1317 | if(tmpMap==NULL){ |
---|
1318 | nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); |
---|
1319 | if(e!=NULL){ |
---|
1320 | if(strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0) |
---|
1321 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
1322 | else |
---|
1323 | if(strncasecmp(e->format,"COMPLEXOUTPUT",strlen(e->format))==0) |
---|
1324 | nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); |
---|
1325 | else |
---|
1326 | nc3=xmlNewNode(ns_wps, BAD_CAST e->format); |
---|
1327 | } |
---|
1328 | else{ |
---|
1329 | map* tmpV=getMapFromMaps(m,"format","value"); |
---|
1330 | if(tmpV!=NULL) |
---|
1331 | nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); |
---|
1332 | else |
---|
1333 | nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData"); |
---|
1334 | } |
---|
1335 | tmp=m->content; |
---|
1336 | while(tmp!=NULL){ |
---|
1337 | if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 && |
---|
1338 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1339 | strncasecmp(tmp->name,"asReference",strlen(tmp->name))!=0 && |
---|
1340 | strncasecmp(tmp->name,"status",strlen(tmp->name))!=0 && |
---|
1341 | strncasecmp(tmp->name,"storeExecuteResponse",strlen(tmp->name))!=0 && |
---|
1342 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1343 | strncasecmp(tmp->name,"format",strlen(tmp->name))!=0 && |
---|
1344 | strncasecmp(tmp->name,"Title",strlen(tmp->name))!=0 && |
---|
1345 | strncasecmp(tmp->name,"Abstract",strlen(tmp->name))!=0 && |
---|
1346 | strncasecmp(tmp->name,"size",strlen(tmp->name))!=0) |
---|
1347 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1348 | tmp=tmp->next; |
---|
1349 | xmlAddChild(nc2,nc3); |
---|
1350 | } |
---|
1351 | if(e!=NULL) |
---|
1352 | tmp=getMap(e->defaults->content,"mimeType"); |
---|
1353 | else |
---|
1354 | tmp=NULL; |
---|
1355 | map* tmp1=getMap(m->content,"encoding"); |
---|
1356 | map* tmp2=getMap(m->content,"mimeType"); |
---|
1357 | map* toto=getMap(m->content,"value"); |
---|
1358 | if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) |
---|
1359 | || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 |
---|
1360 | || strncmp(tmp2->value,"application/",6)==0)) ){ |
---|
1361 | map* rs=getMap(m->content,"size"); |
---|
1362 | bool isSized=true; |
---|
1363 | if(rs==NULL){ |
---|
1364 | char tmp1[1024]; |
---|
1365 | sprintf(tmp1,"%d",strlen(toto->value)); |
---|
1366 | rs=createMap("z",tmp1); |
---|
1367 | isSized=false; |
---|
1368 | } |
---|
1369 | xmlAddChild(nc3,xmlNewText(BAD_CAST base64((const unsigned char*)toto->value,atoi(rs->value)))); |
---|
1370 | if(!isSized){ |
---|
1371 | freeMap(&rs); |
---|
1372 | free(rs); |
---|
1373 | } |
---|
1374 | } |
---|
1375 | else if(tmp!=NULL){ |
---|
1376 | if(strncmp(tmp->value,"text/js",4)==0 || |
---|
1377 | strncmp(tmp->value,"application/js",14)==0) |
---|
1378 | xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value))); |
---|
1379 | else |
---|
1380 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
1381 | xmlAddChild(nc2,nc3); |
---|
1382 | } |
---|
1383 | else |
---|
1384 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
1385 | } |
---|
1386 | else{ |
---|
1387 | nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); |
---|
1388 | xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
1389 | tmp=m->content; |
---|
1390 | while(tmp!=NULL){ |
---|
1391 | if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 && |
---|
1392 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1393 | strncasecmp(tmp->name,"asReference",strlen(tmp->name))!=0 && |
---|
1394 | strncasecmp(tmp->name,"status",strlen(tmp->name))!=0 && |
---|
1395 | strncasecmp(tmp->name,"storeExecuteResponse",strlen(tmp->name))!=0 && |
---|
1396 | strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 && |
---|
1397 | strncasecmp(tmp->name,"format",strlen(tmp->name))!=0 && |
---|
1398 | strncasecmp(tmp->name,"Title",strlen(tmp->name))!=0 && |
---|
1399 | strncasecmp(tmp->name,"Abstract",strlen(tmp->name))!=0 && |
---|
1400 | strncasecmp(tmp->name,"size",strlen(tmp->name))!=0) |
---|
1401 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
1402 | tmp=tmp->next; |
---|
1403 | xmlAddChild(nc2,nc3); |
---|
1404 | } |
---|
1405 | } |
---|
1406 | |
---|
1407 | xmlAddChild(nc1,nc2); |
---|
1408 | xmlAddChild(nc,nc1); |
---|
1409 | |
---|
1410 | } |
---|
1411 | |
---|
1412 | void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){ |
---|
1413 | xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
1414 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
1415 | xmlAddChild(root,nc2); |
---|
1416 | map* tmp=amap; |
---|
1417 | char *tmp2[2]; |
---|
1418 | tmp2[0]="Title"; |
---|
1419 | tmp2[1]="Abstract"; |
---|
1420 | int j=0; |
---|
1421 | for(j=0;j<2;j++){ |
---|
1422 | map* tmp1=getMap(tmp,tmp2[j]); |
---|
1423 | if(tmp1!=NULL){ |
---|
1424 | nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); |
---|
1425 | xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); |
---|
1426 | xmlAddChild(root,nc2); |
---|
1427 | } |
---|
1428 | } |
---|
1429 | } |
---|
1430 | |
---|
1431 | char* getEncoding(maps* m){ |
---|
1432 | if(m!=NULL){ |
---|
1433 | map* tmp=getMap(m->content,"encoding"); |
---|
1434 | if(tmp!=NULL){ |
---|
1435 | return tmp->value; |
---|
1436 | } |
---|
1437 | else |
---|
1438 | return "UTF-8"; |
---|
1439 | } |
---|
1440 | else |
---|
1441 | return "UTF-8"; |
---|
1442 | } |
---|
1443 | |
---|
1444 | char* getVersion(maps* m){ |
---|
1445 | if(m!=NULL){ |
---|
1446 | map* tmp=getMap(m->content,"version"); |
---|
1447 | if(tmp!=NULL){ |
---|
1448 | return tmp->value; |
---|
1449 | } |
---|
1450 | else |
---|
1451 | return "1.0.0"; |
---|
1452 | } |
---|
1453 | else |
---|
1454 | return "1.0.0"; |
---|
1455 | } |
---|
1456 | |
---|
1457 | void printExceptionReportResponse(maps* m,map* s){ |
---|
1458 | int buffersize; |
---|
1459 | xmlDocPtr doc; |
---|
1460 | xmlChar *xmlbuff; |
---|
1461 | xmlNodePtr n; |
---|
1462 | |
---|
1463 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
1464 | maps* tmpMap=getMaps(m,"main"); |
---|
1465 | char *encoding=getEncoding(tmpMap); |
---|
1466 | if(m!=NULL){ |
---|
1467 | map *tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
1468 | if(tmpSid!=NULL){ |
---|
1469 | if( getpid()==atoi(tmpSid->value) ) |
---|
1470 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1471 | } |
---|
1472 | else |
---|
1473 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1474 | }else |
---|
1475 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
1476 | n=createExceptionReportNode(m,s,1); |
---|
1477 | xmlDocSetRootElement(doc, n); |
---|
1478 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
1479 | printf("%s",xmlbuff); |
---|
1480 | fflush(stdout); |
---|
1481 | xmlFreeDoc(doc); |
---|
1482 | xmlFree(xmlbuff); |
---|
1483 | xmlCleanupParser(); |
---|
1484 | zooXmlCleanupNs(); |
---|
1485 | } |
---|
1486 | |
---|
1487 | xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ |
---|
1488 | |
---|
1489 | int buffersize; |
---|
1490 | xmlChar *xmlbuff; |
---|
1491 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
1492 | xmlNodePtr n,nc,nc1,nc2; |
---|
1493 | |
---|
1494 | maps* tmpMap=getMaps(m,"main"); |
---|
1495 | |
---|
1496 | int nsid=zooXmlAddNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
1497 | ns=usedNs[nsid]; |
---|
1498 | n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); |
---|
1499 | |
---|
1500 | if(use_ns==1){ |
---|
1501 | ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
1502 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
1503 | ns_xsi=usedNs[xsiId]; |
---|
1504 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
1505 | ns_xlink=usedNs[xlinkId]; |
---|
1506 | 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"); |
---|
1507 | } |
---|
1508 | addLangAttr(n,m); |
---|
1509 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); |
---|
1510 | |
---|
1511 | nc = xmlNewNode(ns, BAD_CAST "Exception"); |
---|
1512 | |
---|
1513 | map* tmp=getMap(s,"code"); |
---|
1514 | if(tmp!=NULL) |
---|
1515 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); |
---|
1516 | else |
---|
1517 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); |
---|
1518 | |
---|
1519 | tmp=getMap(s,"text"); |
---|
1520 | nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); |
---|
1521 | nc2=NULL; |
---|
1522 | if(tmp!=NULL){ |
---|
1523 | xmlNodeSetContent(nc1, BAD_CAST tmp->value); |
---|
1524 | } |
---|
1525 | else{ |
---|
1526 | xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); |
---|
1527 | } |
---|
1528 | xmlAddChild(nc,nc1); |
---|
1529 | xmlAddChild(n,nc); |
---|
1530 | return n; |
---|
1531 | } |
---|
1532 | |
---|
1533 | |
---|
1534 | void outputResponse(service* s,maps* request_inputs,maps* request_outputs, |
---|
1535 | map* request_inputs1,int cpid,maps* m,int res){ |
---|
1536 | #ifdef DEBUG |
---|
1537 | dumpMaps(request_inputs); |
---|
1538 | dumpMaps(request_outputs); |
---|
1539 | fprintf(stderr,"printProcessResponse\n"); |
---|
1540 | #endif |
---|
1541 | map* toto=getMap(request_inputs1,"RawDataOutput"); |
---|
1542 | int asRaw=0; |
---|
1543 | if(toto!=NULL) |
---|
1544 | asRaw=1; |
---|
1545 | |
---|
1546 | if(asRaw==0){ |
---|
1547 | #ifdef DEBUG |
---|
1548 | fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); |
---|
1549 | dumpMaps(request_outputs); |
---|
1550 | #endif |
---|
1551 | toto=getMap(request_outputs->content,"asReference"); |
---|
1552 | if(toto!=NULL && strcasecmp(toto->value,"true")==0){ |
---|
1553 | toto=getMap(request_outputs->content,"extension"); |
---|
1554 | map *tmp1=getMapFromMaps(m,"main","tmpPath"); |
---|
1555 | char *file_name; |
---|
1556 | bool hasExt=true; |
---|
1557 | if(toto==NULL){ |
---|
1558 | // We can fallback to a default list of supported formats using |
---|
1559 | // mimeType information if present here. Maybe we can add more formats |
---|
1560 | // here. |
---|
1561 | // If mimeType was not found, we then set txt as the default extension. |
---|
1562 | map* mtype=getMap(request_outputs->content,"mimeType"); |
---|
1563 | if(mtype!=NULL){ |
---|
1564 | if(strcasecmp(mtype->value,"text/xml")==0) |
---|
1565 | toto=createMap("extension","xml"); |
---|
1566 | else |
---|
1567 | toto=createMap("extension","txt"); |
---|
1568 | } |
---|
1569 | else |
---|
1570 | toto=createMap("extension","txt"); |
---|
1571 | hasExt=false; |
---|
1572 | } |
---|
1573 | file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char)); |
---|
1574 | sprintf(file_name,"%s/%s_%i.%s",tmp1->value,s->name,cpid+100000,toto->value); |
---|
1575 | FILE *ofile=fopen(file_name,"w"); |
---|
1576 | if(ofile==NULL) |
---|
1577 | fprintf(stderr,"Unable to create file on disk implying segfault ! \n"); |
---|
1578 | map *tmp2=getMapFromMaps(m,"main","tmpUrl"); |
---|
1579 | map *tmp3=getMapFromMaps(m,"main","serverAddress"); |
---|
1580 | char *file_url; |
---|
1581 | file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char)); |
---|
1582 | sprintf(file_url,"%s/%s/%s_%i.%s",tmp3->value,tmp2->value,s->name,cpid+100000,toto->value); |
---|
1583 | addToMap(request_outputs->content,"Reference",file_url); |
---|
1584 | if(hasExt!=true){ |
---|
1585 | freeMap(&toto); |
---|
1586 | free(toto); |
---|
1587 | } |
---|
1588 | toto=getMap(request_outputs->content,"value"); |
---|
1589 | if(toto!=NULL && toto->value!=NULL) |
---|
1590 | fwrite(toto->value,1,(strlen(toto->value)+1)*sizeof(char),ofile); |
---|
1591 | fclose(ofile); |
---|
1592 | free(file_name); |
---|
1593 | free(file_url); |
---|
1594 | } |
---|
1595 | map *r_inputs=getMap(s->content,"serviceProvider"); |
---|
1596 | #ifdef DEBUG |
---|
1597 | fprintf(stderr,"SERVICE : %s\n",r_inputs->value); |
---|
1598 | dumpMaps(m); |
---|
1599 | #endif |
---|
1600 | printProcessResponse(m,request_inputs1,cpid, |
---|
1601 | s,r_inputs->value,res, |
---|
1602 | request_inputs, |
---|
1603 | request_outputs); |
---|
1604 | } |
---|
1605 | else |
---|
1606 | if(res!=SERVICE_FAILED){ |
---|
1607 | /** |
---|
1608 | * We get the requested output or fallback to the first one if the |
---|
1609 | * requested one is not present in the resulting outputs maps. |
---|
1610 | */ |
---|
1611 | maps* tmpI=NULL; |
---|
1612 | map* tmpIV=getMap(request_inputs1,"RawDataOutput"); |
---|
1613 | if(tmpIV!=NULL){ |
---|
1614 | tmpI=getMaps(request_outputs,tmpIV->value); |
---|
1615 | } |
---|
1616 | if(tmpI==NULL) |
---|
1617 | tmpI=request_outputs; |
---|
1618 | toto=getMap(tmpI->content,"value"); |
---|
1619 | if(toto==NULL){ |
---|
1620 | map * errormap = createMap("text",_("Unable to fetch any result")); |
---|
1621 | addToMap(errormap,"code", "InternalError"); |
---|
1622 | printExceptionReportResponse(m,errormap); |
---|
1623 | freeMap(&errormap); |
---|
1624 | free(errormap); |
---|
1625 | } |
---|
1626 | char mime[1024]; |
---|
1627 | map* mi=getMap(tmpI->content,"mimeType"); |
---|
1628 | #ifdef DEBUG |
---|
1629 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
1630 | dumpMaps(request_outputs); |
---|
1631 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
1632 | #endif |
---|
1633 | map* en=getMap(tmpI->content,"encoding"); |
---|
1634 | if(mi!=NULL && en!=NULL) |
---|
1635 | sprintf(mime, |
---|
1636 | "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", |
---|
1637 | mi->value,en->value); |
---|
1638 | else |
---|
1639 | if(mi!=NULL) |
---|
1640 | sprintf(mime, |
---|
1641 | "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", |
---|
1642 | mi->value); |
---|
1643 | else |
---|
1644 | sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); |
---|
1645 | printf("%s",mime); |
---|
1646 | if(mi!=NULL && strncmp(mi->value,"image",5)==0){ |
---|
1647 | map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); |
---|
1648 | fwrite(toto->value,atoi(rs->value),1,stdout); |
---|
1649 | } |
---|
1650 | else |
---|
1651 | printf("%s",toto->value); |
---|
1652 | #ifdef DEBUG |
---|
1653 | dumpMap(toto); |
---|
1654 | #endif |
---|
1655 | }else{ |
---|
1656 | char tmp[1024]; |
---|
1657 | map * errormap; |
---|
1658 | map *lenv; |
---|
1659 | lenv=getMapFromMaps(m,"lenv","message"); |
---|
1660 | if(lenv!=NULL) |
---|
1661 | sprintf(tmp,_("Unable to run the Service. The message returned back by the Service was the following : %s"),lenv->value); |
---|
1662 | else |
---|
1663 | sprintf(tmp,_("Unable to run the Service. No more information was returned back by the Service.")); |
---|
1664 | errormap = createMap("text",tmp); |
---|
1665 | addToMap(errormap,"code", "InternalError"); |
---|
1666 | printExceptionReportResponse(m,errormap); |
---|
1667 | freeMap(&errormap); |
---|
1668 | free(errormap); |
---|
1669 | } |
---|
1670 | } |
---|
1671 | |
---|
1672 | char *base64(const unsigned char *input, int length) |
---|
1673 | { |
---|
1674 | BIO *bmem, *b64; |
---|
1675 | BUF_MEM *bptr; |
---|
1676 | |
---|
1677 | b64 = BIO_new(BIO_f_base64()); |
---|
1678 | bmem = BIO_new(BIO_s_mem()); |
---|
1679 | b64 = BIO_push(b64, bmem); |
---|
1680 | BIO_write(b64, input, length); |
---|
1681 | BIO_flush(b64); |
---|
1682 | BIO_get_mem_ptr(b64, &bptr); |
---|
1683 | |
---|
1684 | char *buff = (char *)malloc(bptr->length); |
---|
1685 | memcpy(buff, bptr->data, bptr->length-1); |
---|
1686 | buff[bptr->length-1] = 0; |
---|
1687 | |
---|
1688 | BIO_free_all(b64); |
---|
1689 | |
---|
1690 | return buff; |
---|
1691 | } |
---|
1692 | |
---|
1693 | char* addDefaultValues(maps** out,elements* in,maps* m,int type){ |
---|
1694 | elements* tmpInputs=in; |
---|
1695 | maps* out1=*out; |
---|
1696 | while(tmpInputs!=NULL){ |
---|
1697 | maps *tmpMaps=getMaps(out1,tmpInputs->name); |
---|
1698 | if(tmpMaps==NULL){ |
---|
1699 | maps* tmpMaps2=(maps*)malloc(MAPS_SIZE); |
---|
1700 | tmpMaps2->name=strdup(tmpInputs->name); |
---|
1701 | tmpMaps2->content=NULL; |
---|
1702 | tmpMaps2->next=NULL; |
---|
1703 | |
---|
1704 | if(type==0){ |
---|
1705 | map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs"); |
---|
1706 | if(tmpMapMinO!=NULL) |
---|
1707 | if(atoi(tmpMapMinO->value)>=1){ |
---|
1708 | freeMaps(&tmpMaps2); |
---|
1709 | free(tmpMaps2); |
---|
1710 | return tmpInputs->name; |
---|
1711 | } |
---|
1712 | else{ |
---|
1713 | if(tmpMaps2->content==NULL) |
---|
1714 | tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value); |
---|
1715 | else |
---|
1716 | addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value); |
---|
1717 | } |
---|
1718 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
1719 | if(tmpMaxO!=NULL) |
---|
1720 | if(tmpMaps2->content==NULL) |
---|
1721 | tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); |
---|
1722 | else |
---|
1723 | addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); |
---|
1724 | } |
---|
1725 | |
---|
1726 | iotype* tmpIoType=tmpInputs->defaults; |
---|
1727 | if(tmpIoType!=NULL){ |
---|
1728 | map* tmpm=tmpIoType->content; |
---|
1729 | while(tmpm!=NULL){ |
---|
1730 | if(tmpMaps2->content==NULL) |
---|
1731 | tmpMaps2->content=createMap(tmpm->name,tmpm->value); |
---|
1732 | else |
---|
1733 | addToMap(tmpMaps2->content,tmpm->name,tmpm->value); |
---|
1734 | tmpm=tmpm->next; |
---|
1735 | } |
---|
1736 | } |
---|
1737 | if(type==1){ |
---|
1738 | map *tmpMap=getMap(tmpMaps2->content,"value"); |
---|
1739 | if(tmpMap==NULL) |
---|
1740 | addToMap(tmpMaps2->content,"value","NULL"); |
---|
1741 | } |
---|
1742 | if(out1==NULL){ |
---|
1743 | *out=dupMaps(&tmpMaps2); |
---|
1744 | out1=*out; |
---|
1745 | } |
---|
1746 | else |
---|
1747 | addMapsToMaps(&out1,tmpMaps2); |
---|
1748 | freeMap(&tmpMaps2->content); |
---|
1749 | free(tmpMaps2->content); |
---|
1750 | tmpMaps2->content=NULL; |
---|
1751 | freeMaps(&tmpMaps2); |
---|
1752 | free(tmpMaps2); |
---|
1753 | tmpMaps2=NULL; |
---|
1754 | } |
---|
1755 | else{ |
---|
1756 | iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name, |
---|
1757 | tmpMaps->content); |
---|
1758 | |
---|
1759 | if(type==0) { |
---|
1760 | map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); |
---|
1761 | if(tmpMap1!=NULL){ |
---|
1762 | if(tmpMaps->content==NULL) |
---|
1763 | tmpMaps->content=createMap("minOccurs",tmpMap1->value); |
---|
1764 | else |
---|
1765 | addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); |
---|
1766 | } |
---|
1767 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
1768 | if(tmpMaxO!=NULL){ |
---|
1769 | if(tmpMaps->content==NULL) |
---|
1770 | tmpMaps->content=createMap("maxOccurs",tmpMap1->value); |
---|
1771 | else |
---|
1772 | addToMap(tmpMaps->content,"maxOccurs",tmpMap1->value); |
---|
1773 | } |
---|
1774 | } |
---|
1775 | |
---|
1776 | if(tmpIoType!=NULL){ |
---|
1777 | map* tmpContent=tmpIoType->content; |
---|
1778 | map* cval=NULL; |
---|
1779 | |
---|
1780 | while(tmpContent!=NULL){ |
---|
1781 | if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){ |
---|
1782 | #ifdef DEBUG |
---|
1783 | fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value); |
---|
1784 | #endif |
---|
1785 | if(tmpMaps->content==NULL) |
---|
1786 | tmpMaps->content=createMap(tmpContent->name,tmpContent->value); |
---|
1787 | else |
---|
1788 | addToMap(tmpMaps->content,tmpContent->name,tmpContent->value); |
---|
1789 | } |
---|
1790 | tmpContent=tmpContent->next; |
---|
1791 | } |
---|
1792 | } |
---|
1793 | } |
---|
1794 | tmpInputs=tmpInputs->next; |
---|
1795 | } |
---|
1796 | return ""; |
---|
1797 | } |
---|