Changeset 601 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Feb 26, 2015, 11:53:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r587 r601 42 42 43 43 #define ERROR_MSG_MAX_LENGTH 1024 44 45 #include "mimetypes.h" 44 46 45 47 /** … … 2184 2186 */ 2185 2187 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){ 2188 2186 2189 xmlNodePtr nc1,nc2,nc3; 2187 2190 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 2191 2194 else 2192 2195 tmp=m->content; 2193 #ifdef DEBUG 2194 dumpMap(tmp); 2195 dumpElements(e); 2196 #endif 2196 2197 2197 nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); 2198 2198 if(e!=NULL) … … 2200 2200 else 2201 2201 nc3=xmlNewText(BAD_CAST m->name); 2202 2202 2203 xmlAddChild(nc2,nc3); 2203 2204 xmlAddChild(nc1,nc2); … … 2219 2220 else 2220 2221 tmp=getMap(m->content,"Abstract"); 2222 2221 2223 if(tmp!=NULL){ 2222 2224 nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); … … 2230 2232 * IO type Reference or full Data ? 2231 2233 */ 2232 #ifdef DEBUG2233 fprintf(stderr,"FORMAT %s %s\n",e->format,e->format);2234 #endif2235 2234 map *tmpMap=getMap(m->content,"Reference"); 2236 2235 if(tmpMap==NULL){ … … 2238 2237 if(e!=NULL){ 2239 2238 if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0) 2240 2239 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2241 2240 else 2242 2243 nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");2244 else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)2245 nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");2246 else2247 nc3=xmlNewNode(ns_wps, BAD_CAST e->format);2248 } 2249 else {2241 if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) 2242 nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); 2243 else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0) 2244 nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); 2245 else 2246 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 2247 } 2248 else { 2250 2249 map* tmpV=getMapFromMaps(m,"format","value"); 2251 2250 if(tmpV!=NULL) 2252 nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);2251 nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); 2253 2252 else 2254 nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData");2253 nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData"); 2255 2254 } 2256 2255 tmp=m->content; 2257 #ifdef USE_MS 2258 map* testMap=getMap(tmp,"requestedMimeType"); 2259 #endif 2256 2260 2257 while(tmp!=NULL){ 2261 2258 if(strcasecmp(tmp->name,"mimeType")==0 || 2262 strcasecmp(tmp->name,"encoding")==0 || 2263 strcasecmp(tmp->name,"schema")==0 || 2264 strcasecmp(tmp->name,"datatype")==0 || 2265 strcasecmp(tmp->name,"uom")==0){ 2266 #ifdef USE_MS 2267 if(testMap==NULL || (testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)==0)){ 2268 #endif 2269 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 2270 #ifdef USE_MS 2271 } 2272 else 2273 if(strcasecmp(tmp->name,"mimeType")==0){ 2274 if(testMap!=NULL) 2275 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); 2276 else 2277 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 2278 } 2279 #endif 2259 strcasecmp(tmp->name,"encoding")==0 || 2260 strcasecmp(tmp->name,"schema")==0 || 2261 strcasecmp(tmp->name,"datatype")==0 || 2262 strcasecmp(tmp->name,"uom")==0) { 2263 2264 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 2280 2265 } 2281 2266 tmp=tmp->next; 2282 2267 xmlAddChild(nc2,nc3); 2283 2268 } 2284 if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {2269 if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) { 2285 2270 map* bb=getMap(m->content,"value"); 2286 if(bb!=NULL){ 2287 map* tmpRes=parseBoundingBox(bb->value); 2288 printBoundingBox(ns_ows,nc3,tmpRes); 2289 freeMap(&tmpRes); 2290 free(tmpRes); 2291 } 2292 }else{ 2271 if(bb!=NULL) { 2272 map* tmpRes=parseBoundingBox(bb->value); 2273 printBoundingBox(ns_ows,nc3,tmpRes); 2274 freeMap(&tmpRes); 2275 free(tmpRes); 2276 } 2277 } 2278 else { 2293 2279 if(e!=NULL) 2294 tmp=getMap(e->defaults->content,"mimeType");2280 tmp=getMap(e->defaults->content,"mimeType"); 2295 2281 else 2296 tmp=NULL; 2297 #ifdef USE_MS 2298 /** 2299 * In case of OGC WebServices output use, as the data was requested 2300 * with asReference=false we have to download the resulting OWS request 2301 * stored in the Reference map value. 2302 */ 2303 map* testMap=getMap(m->content,"requestedMimeType"); 2304 if(testMap!=NULL){ 2305 HINTERNET hInternet; 2306 char* tmpValue; 2307 size_t dwRead; 2308 hInternet=InternetOpen( 2309 #ifndef WIN32 2310 (LPCTSTR) 2311 #endif 2312 "ZooWPSClient\0", 2313 INTERNET_OPEN_TYPE_PRECONFIG, 2314 NULL,NULL, 0); 2315 testMap=getMap(m->content,"Reference"); 2316 loadRemoteFile(&m,&m->content,&hInternet,testMap->value); 2317 processDownloads(&hInternet); 2318 tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char)); 2319 InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead); 2320 InternetCloseHandle(&hInternet); 2321 } 2322 #endif 2323 map* tmp1=getMap(m->content,"encoding"); 2324 map* tmp2=getMap(m->content,"mimeType"); 2325 map* tmp3=getMap(m->content,"value"); 2326 int hasValue=1; 2327 if(tmp3==NULL){ 2328 tmp3=createMap("value",""); 2329 hasValue=-1; 2330 } 2331 if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) 2332 || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 || 2333 (strncmp(tmp2->value,"application/",12)==0 && 2334 strncmp(tmp2->value,"application/json",16)!=0&& 2335 strncmp(tmp2->value,"application/x-javascript",24)!=0&& 2336 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0)) 2337 )) { 2338 map* rs=getMap(m->content,"size"); 2339 bool isSized=true; 2340 if(rs==NULL){ 2341 char tmp1[1024]; 2342 sprintf(tmp1,"%ld",strlen(tmp3->value)); 2343 rs=createMap("size",tmp1); 2344 isSized=false; 2345 } 2346 2347 xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value)))); 2348 if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) 2349 xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64"); 2350 if(!isSized){ 2351 freeMap(&rs); 2352 free(rs); 2353 } 2354 } 2355 else if(tmp2!=NULL){ 2356 if(strncmp(tmp2->value,"text/js",7)==0 || 2357 strncmp(tmp2->value,"application/json",16)==0) 2358 xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); 2359 else{ 2360 if(strncmp(tmp2->value,"text/xml",8)==0 || 2361 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)==0){ 2362 int li=zooXmlAddDoc(tmp3->value); 2363 xmlDocPtr doc = iDocs[li]; 2364 xmlNodePtr ir = xmlDocGetRootElement(doc); 2365 xmlAddChild(nc3,ir); 2366 } 2367 else 2282 tmp=NULL; 2283 2284 map* tmp1=getMap(m->content,"encoding"); 2285 map* tmp2=getMap(m->content,"mimeType"); 2286 map* tmp3=getMap(m->content,"value"); 2287 int hasValue=1; 2288 if(tmp3==NULL){ 2289 tmp3=createMap("value",""); 2290 hasValue=-1; 2291 } 2292 2293 if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 ) // if encoding is base64 2294 || // or if 2295 ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL // mime type is not text 2296 && // nor 2297 strstr(tmp2->value,"xml") == NULL // xml 2298 && // nor 2299 strstr(tmp2->value,"javascript") == NULL // javascript 2300 && 2301 strstr(tmp2->value,"json") == NULL 2302 && 2303 strstr(tmp2->value,"ecmascript") == NULL 2304 && 2305 // include for backwards compatibility, 2306 // although correct mime type is ...kml+xml: 2307 strstr(tmp2->value,"google-earth.kml") == NULL 2308 ) 2309 ) 2310 ) { // then 2311 map* rs=getMap(m->content,"size"); // obtain size 2312 bool isSized=true; 2313 if(rs==NULL){ 2314 char tmp1[1024]; 2315 sprintf(tmp1,"%ld",strlen(tmp3->value)); 2316 rs=createMap("size",tmp1); 2317 isSized=false; 2318 } 2319 2320 xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value)))); // base 64 encode in XML 2321 2322 if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) { 2323 xmlAttrPtr ap = xmlHasProp(nc3, BAD_CAST "encoding"); 2324 if (ap != NULL) { 2325 xmlRemoveProp(ap); 2326 } 2327 xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64"); 2328 } 2329 2330 if(!isSized){ 2331 freeMap(&rs); 2332 free(rs); 2333 } 2334 } 2335 else if (tmp2!=NULL) { // else (text-based format) 2336 if(strstr(tmp2->value, "javascript") != NULL || // if javascript put code in CDATA block 2337 strstr(tmp2->value, "json") != NULL || // (will not be parsed by XML reader) 2338 strstr(tmp2->value, "ecmascript") != NULL 2339 ) { 2340 xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); 2341 } 2342 else { // else 2343 if (strstr(tmp2->value, "xml") != NULL || // if XML-based format 2344 // include for backwards compatibility, 2345 // although correct mime type is ...kml+xml: 2346 strstr(tmp2->value, "google-earth.kml") != NULL 2347 ) { 2348 2349 int li=zooXmlAddDoc(tmp3->value); 2350 xmlDocPtr doc = iDocs[li]; 2351 xmlNodePtr ir = xmlDocGetRootElement(doc); 2352 xmlAddChild(nc3,ir); 2353 } 2354 else // else 2355 xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value)); // add text node 2356 } 2357 xmlAddChild(nc2,nc3); 2358 } 2359 else { 2368 2360 xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value)); 2369 } 2370 xmlAddChild(nc2,nc3); 2371 } 2372 else{ 2373 xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value)); 2374 } 2375 if(hasValue<0){ 2376 freeMap(&tmp3); 2377 free(tmp3); 2378 } 2379 } 2380 } 2381 else{ 2361 } 2362 2363 if(hasValue<0) { 2364 freeMap(&tmp3); 2365 free(tmp3); 2366 } 2367 } 2368 } 2369 else { // Reference 2382 2370 tmpMap=getMap(m->content,"Reference"); 2383 2371 nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); … … 2386 2374 else 2387 2375 xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value); 2388 tmp=m->content; 2389 #ifdef USE_MS 2390 map* testMap=getMap(tmp,"requestedMimeType"); 2391 #endif 2392 while(tmp!=NULL){ 2376 2377 tmp=m->content; 2378 while(tmp!=NULL) { 2393 2379 if(strcasecmp(tmp->name,"mimeType")==0 || 2394 strcasecmp(tmp->name,"encoding")==0 || 2395 strcasecmp(tmp->name,"schema")==0 || 2396 strcasecmp(tmp->name,"datatype")==0 || 2397 strcasecmp(tmp->name,"uom")==0){ 2398 #ifdef USE_MS 2399 if(testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)!=0){ 2400 if(strcasecmp(tmp->name,"mimeType")==0) 2401 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); 2402 } 2403 else 2404 #endif 2405 if(strcasecmp(tmp->name,"datatype")==0) 2406 xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain"); 2407 else 2408 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 2380 strcasecmp(tmp->name,"encoding")==0 || 2381 strcasecmp(tmp->name,"schema")==0 || 2382 strcasecmp(tmp->name,"datatype")==0 || 2383 strcasecmp(tmp->name,"uom")==0){ 2384 2385 if(strcasecmp(tmp->name,"datatype")==0) 2386 xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain"); 2387 else 2388 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 2409 2389 } 2410 2390 tmp=tmp->next; … … 2414 2394 xmlAddChild(nc1,nc2); 2415 2395 xmlAddChild(nc,nc1); 2416 2417 2396 } 2418 2397 … … 2808 2787 map *ext=getMap(tmpI->content,"extension"); 2809 2788 char *file_path; 2810 bool hasExt=true; 2811 if(ext==NULL){ 2812 // We can fallback to a default list of supported formats using 2813 // mimeType information if present here. Maybe we can add more formats 2814 // here. 2815 // If mimeType was not found, we then set txt as the default extension 2789 char file_ext[32]; 2790 2791 if( ext != NULL && ext->value != NULL) { 2792 strncpy(file_ext, ext->value, 32); 2793 } 2794 else { 2795 // Obtain default file extension (see mimetypes.h). 2796 // If the MIME type is not recognized, txt is used as the default extension 2816 2797 map* mtype=getMap(tmpI->content,"mimeType"); 2817 if(mtype!=NULL) { 2818 if(strncasecmp(mtype->value,"text/xml",8)==0) 2819 ext=createMap("extension","xml"); 2820 else if(strncasecmp(mtype->value,"application/zip",15)==0) 2821 ext=createMap("extension","zip"); 2822 else if(strncasecmp(mtype->value,"application/json",16)==0) 2823 ext=createMap("extension","js"); 2824 else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0) 2825 ext=createMap("extension","kml"); 2826 else if(strncmp(mtype->value,"image/",6)==0) 2827 ext=createMap("extension",strstr(mtype->value,"/")+1); 2828 else if(strcasecmp(mtype->value,"text/html")==0) 2829 ext=createMap("extension","html"); 2830 else 2831 ext=createMap("extension","txt"); 2832 } 2833 else 2834 ext=createMap("extension","txt"); 2835 hasExt=false; 2798 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2836 2799 } 2837 file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char)); 2838 int cpid0=cpid+time(NULL); 2839 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value); 2800 2801 file_name=(char*)malloc((strlen(s->name)+strlen(file_ext)+strlen(tmpI->name)+1024)*sizeof(char)); 2802 int cpid0=cpid+time(NULL); 2803 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,file_ext); 2840 2804 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2841 2805 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2842 FILE *ofile=fopen(file_path,"wb"); 2806 2807 FILE *ofile=fopen(file_path,"wb"); 2843 2808 if(ofile==NULL){ 2844 2809 char tmpMsg[1024]; … … 2850 2815 } 2851 2816 free(file_path); 2852 if(!hasExt){ 2853 freeMap(&ext); 2854 free(ext); 2855 } 2817 2856 2818 toto=getMap(tmpI->content,"value"); 2857 2819 if(strcasecmp(format,"BoundingBoxData")!=0){
Note: See TracChangeset
for help on using the changeset viewer.