Changeset 601 for trunk


Ignore:
Timestamp:
Feb 26, 2015, 11:53:34 AM (9 years ago)
Author:
knut
Message:

Implemented default result file extensions for many MIME types, based on Apache's mime.types list. Added file mimetypes.h. Made function printIOType more general with respect to media content. Rewrote the XML parsing of the <ResponseDocument?> block in Execute requests to fix problem caused by one output variable inheriting properties from another. Minor memory allocation modification in zoo_loader.c.

Location:
trunk/zoo-project/zoo-kernel
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/Makefile.in

    r559 r601  
    3333        gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c
    3434
    35 service_internal.o: service_internal.c service.h
     35service_internal.o: service_internal.c service.h mimetypes.h
    3636        g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
    3737
  • trunk/zoo-project/zoo-kernel/makefile.vc

    r582 r601  
    4141        $(CPP) $(CFLAGS) /c zcfg2yaml.c
    4242
    43 service_internal.obj: service_internal.c
     43service_internal.obj: service_internal.c mimetypes.h
    4444        $(CPP) $(CFLAGS) /c service_internal.c
    4545
  • trunk/zoo-project/zoo-kernel/service.h

    r579 r601  
    252252    }
    253253  }
    254 
     254 
    255255  /**
    256256   * Dump a maps on stderr, see dumpMap().
     
    283283    fclose(file);
    284284  }
    285 
     285 
    286286  /**
    287287   * Create a new map
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r587 r601  
    4242
    4343#define ERROR_MSG_MAX_LENGTH 1024
     44
     45#include "mimetypes.h"
    4446
    4547/**
     
    21842186 */
    21852187void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){
     2188
    21862189  xmlNodePtr nc1,nc2,nc3;
    21872190  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    21912194  else
    21922195    tmp=m->content;
    2193 #ifdef DEBUG
    2194   dumpMap(tmp);
    2195   dumpElements(e);
    2196 #endif
     2196
    21972197  nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
    21982198  if(e!=NULL)
     
    22002200  else
    22012201    nc3=xmlNewText(BAD_CAST m->name);
     2202
    22022203  xmlAddChild(nc2,nc3);
    22032204  xmlAddChild(nc1,nc2);
     
    22192220  else
    22202221    tmp=getMap(m->content,"Abstract");
     2222
    22212223  if(tmp!=NULL){
    22222224    nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
     
    22302232   * IO type Reference or full Data ?
    22312233   */
    2232 #ifdef DEBUG
    2233   fprintf(stderr,"FORMAT %s %s\n",e->format,e->format);
    2234 #endif
    22352234  map *tmpMap=getMap(m->content,"Reference");
    22362235  if(tmpMap==NULL){
     
    22382237    if(e!=NULL){
    22392238      if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
    2240         nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     2239         nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
    22412240      else
    2242         if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
    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         else
    2247           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 {
    22502249      map* tmpV=getMapFromMaps(m,"format","value");
    22512250      if(tmpV!=NULL)
    2252         nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
     2251            nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
    22532252      else
    2254         nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData");
     2253            nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData");
    22552254    }
    22562255    tmp=m->content;
    2257 #ifdef USE_MS
    2258     map* testMap=getMap(tmp,"requestedMimeType");
    2259 #endif
     2256
    22602257    while(tmp!=NULL){
    22612258      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);
    22802265      }
    22812266      tmp=tmp->next;
    22822267      xmlAddChild(nc2,nc3);
    22832268    }
    2284     if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
     2269    if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
    22852270      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 {
    22932279      if(e!=NULL)
    2294         tmp=getMap(e->defaults->content,"mimeType");
     2280            tmp=getMap(e->defaults->content,"mimeType");
    22952281      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 {
    23682360            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
    23822370    tmpMap=getMap(m->content,"Reference");
    23832371    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
     
    23862374    else
    23872375      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) {
    23932379      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);
    24092389      }
    24102390      tmp=tmp->next;
     
    24142394  xmlAddChild(nc1,nc2);
    24152395  xmlAddChild(nc,nc1);
    2416 
    24172396}
    24182397
     
    28082787            map *ext=getMap(tmpI->content,"extension");
    28092788            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
    28162797              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);
    28362799            }
    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);
    28402804            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
    28412805            sprintf(file_path,"%s/%s",tmp1->value,file_name);
    2842             FILE *ofile=fopen(file_path,"wb");
     2806           
     2807                FILE *ofile=fopen(file_path,"wb");
    28432808            if(ofile==NULL){
    28442809              char tmpMsg[1024];
     
    28502815            }
    28512816            free(file_path);
    2852             if(!hasExt){
    2853               freeMap(&ext);
    2854               free(ext);
    2855             }
     2817
    28562818            toto=getMap(tmpI->content,"value");
    28572819            if(strcasecmp(format,"BoundingBoxData")!=0){
  • trunk/zoo-project/zoo-kernel/zoo_loader.c

    r587 r601  
    8484  fflush(stderr);
    8585#endif
    86 
    8786 
    8887  char *strQuery=NULL;
     
    134133          char *ivalue=new char[cgiContentLength];
    135134          cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength);
    136           char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+1)*sizeof(char));
     135          char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+2)*sizeof(char));       
    137136          sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
    138           if(strlen(buffer)==0){
     137
     138          if(strlen(buffer)==0){               
    139139            sprintf(buffer,"%s",tmpValueFinal);
    140           }else{
     140          }else{               
    141141            char *tmp=zStrdup(buffer);
    142142            sprintf(buffer,"%s&%s",tmp,tmpValueFinal);
    143143            free(tmp);
    144           }
     144          }       
    145145          free(tmpValueFinal);
    146146#ifdef DEBUG
     
    149149          delete[]ivalue;
    150150          arrayStep++;
    151         }
     151        }       
    152152        if(tmpMap!=NULL)
    153153          addToMap(tmpMap,"request",buffer);
     
    156156      }
    157157      delete[]buffer;
    158     }
     158    }   
    159159  }
    160160  else{
     
    344344          value=zStrdup(token1);
    345345        token1=strtok_r(NULL,"=",&saveptr1);
    346       }
     346      }   
    347347      //addToMap(tmpMap,name,value);
    348348          /* knut: strtok(_r) ignores delimiter bytes at start and end of string;
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r587 r601  
    18671867      fflush (stderr);
    18681868#endif
     1869
    18691870    /**
    18701871     * Parse every Input in DataInputs node.
     
    23342335
    23352336                          map *test = getMap (tmpmaps->content, "encoding");
     2337
    23362338                          if (test == NULL)
    2337                             {
     2339                            { 
    23382340                              if (tmpmaps->content != NULL)
    23392341                                addToMap (tmpmaps->content, "encoding",
     
    23462348
    23472349                          if (strcasecmp (test->value, "base64") != 0)
    2348                             {
     2350                            { 
    23492351                              xmlChar *mv = xmlNodeListGetString (doc,
    23502352                                                                  cur4->
     
    23812383                                                size);
    23822384                                      xmlFreeDoc (doc1);
    2383                                     }
     2385                                    }                                                                   
    23842386                                }
    23852387                              if (mv != NULL)
     
    25762578        }
    25772579      else
    2578         for (int k = 0; k < tmps->nodeNr; k++)
    2579           {
    2580             //else
    2581             addToMap (request_inputs, "ResponseDocument", "");
    2582             maps *tmpmaps = NULL;
    2583             xmlNodePtr cur = tmps->nodeTab[k];
    2584             if (cur->type == XML_ELEMENT_NODE)
    2585               {
    2586           /**
    2587            * A specific responseDocument node.
    2588            */
    2589                 if (tmpmaps == NULL)
    2590                   {
    2591                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2592                     if (tmpmaps == NULL)
    2593                       {
    2594                         return errorException (m,
    2595                                                _
    2596                                                ("Unable to allocate memory."),
    2597                                                "InternalError", NULL);
    2598                       }
    2599                     tmpmaps->name = zStrdup ("unknownIdentifier");
    2600                     tmpmaps->content = NULL;
    2601                     tmpmaps->next = NULL;
    2602                   }
    2603           /**
    2604            * Get every attribute: storeExecuteResponse, lineage, status
    2605            */
    2606                 const char *ress[3] =
    2607                   { "storeExecuteResponse", "lineage", "status" };
    2608                 xmlChar *val;
    2609                 for (int l = 0; l < 3; l++)
    2610                   {
    2611 #ifdef DEBUG
    2612                     fprintf (stderr, "*** %s ***\t", ress[l]);
    2613 #endif
    2614                     val = xmlGetProp (cur, BAD_CAST ress[l]);
    2615                     if (val != NULL && strlen ((char *) val) > 0)
    2616                       {
    2617                         if (tmpmaps->content != NULL)
    2618                           addToMap (tmpmaps->content, ress[l], (char *) val);
    2619                         else
    2620                           tmpmaps->content =
    2621                             createMap (ress[l], (char *) val);
    2622                         addToMap (request_inputs, ress[l], (char *) val);
    2623                       }
    2624 #ifdef DEBUG
    2625                     fprintf (stderr, "%s\n", val);
    2626 #endif
    2627                     xmlFree (val);
    2628                   }
    2629                 xmlNodePtr cur1 = cur->children;
    2630                 while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
    2631                   cur1 = cur1->next;
    2632                 int cur1cnt = 0;
    2633                 while (cur1)
    2634                   {
    2635             /**
    2636              * Indentifier
    2637              */
    2638                     if (xmlStrncasecmp
    2639                         (cur1->name, BAD_CAST "Identifier",
    2640                          xmlStrlen (cur1->name)) == 0)
    2641                       {
    2642                         xmlChar *val =
    2643                           xmlNodeListGetString (doc, cur1->xmlChildrenNode,
    2644                                                 1);
    2645                         if (tmpmaps == NULL)
    2646                           {
    2647                             tmpmaps = (maps *) malloc (MAPS_SIZE);
    2648                             if (tmpmaps == NULL)
    2649                               {
    2650                                 return errorException (m,
    2651                                                        _
    2652                                                        ("Unable to allocate memory."),
    2653                                                        "InternalError", NULL);
    2654                               }
    2655                             tmpmaps->name = zStrdup ((char *) val);
    2656                             tmpmaps->content = NULL;
    2657                             tmpmaps->next = NULL;
    2658                           }
    2659                         else
    2660                           {
    2661                             free (tmpmaps->name);
    2662                             tmpmaps->name = zStrdup ((char *) val);
    2663                           }
    2664                         if (asRaw == true)
    2665                           addToMap (request_inputs, "RawDataOutput",
    2666                                     (char *) val);
    2667                         else
    2668                           {
    2669                             if (cur1cnt == 0)
    2670                               addToMap (request_inputs, "ResponseDocument",
    2671                                         (char *) val);
    2672                             else
    2673                               {
    2674                                 map *tt =
    2675                                   getMap (request_inputs, "ResponseDocument");
    2676                                 char *tmp = zStrdup (tt->value);
    2677                                 free (tt->value);
    2678                                 tt->value =
    2679                                   (char *)
    2680                                   malloc ((strlen (tmp) +
    2681                                            strlen ((char *) val) +
    2682                                            1) * sizeof (char));
    2683                                 sprintf (tt->value, "%s;%s", tmp,
    2684                                          (char *) val);
    2685                                 free (tmp);
    2686                               }
    2687                           }
    2688                         cur1cnt += 1;
    2689                         xmlFree (val);
    2690                       }
    2691             /**
    2692              * Title, Asbtract
    2693              */
    2694                     else
    2695                       if (xmlStrncasecmp
    2696                           (cur1->name, BAD_CAST "Title",
    2697                            xmlStrlen (cur1->name)) == 0
    2698                           || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract",
    2699                                              xmlStrlen (cur1->name)) == 0)
    2700                       {
    2701                         xmlChar *val =
    2702                           xmlNodeListGetString (doc, cur1->xmlChildrenNode,
    2703                                                 1);
    2704                         if (tmpmaps == NULL)
    2705                           {
    2706                             tmpmaps = (maps *) malloc (MAPS_SIZE);
    2707                             if (tmpmaps == NULL)
    2708                               {
    2709                                 return errorException (m,
    2710                                                        _
    2711                                                        ("Unable to allocate memory."),
    2712                                                        "InternalError", NULL);
    2713                               }
    2714                             tmpmaps->name = zStrdup ("missingIndetifier");
    2715                             tmpmaps->content =
    2716                               createMap ((char *) cur1->name, (char *) val);
    2717                             tmpmaps->next = NULL;
    2718                           }
    2719                         else
    2720                           {
    2721                             if (tmpmaps->content != NULL)
    2722                               addToMap (tmpmaps->content, (char *) cur1->name,
    2723                                         (char *) val);
    2724                             else
    2725                               tmpmaps->content =
    2726                                 createMap ((char *) cur1->name, (char *) val);
    2727                           }
    2728                         xmlFree (val);
    2729                       }
    2730                     else
    2731                       if (xmlStrncasecmp
    2732                           (cur1->name, BAD_CAST "Output",
    2733                            xmlStrlen (cur1->name)) == 0)
    2734                       {
    2735               /**
    2736                * Get every attribute from an Output node
    2737                * mimeType, encoding, schema, uom, asReference
    2738                */
    2739                         const char *outs[5] =
    2740                           { "mimeType", "encoding", "schema", "uom",
    2741                           "asReference"
    2742                         };
    2743                         for (int l = 0; l < 5; l++)
    2744                           {
    2745 #ifdef DEBUG
    2746                             fprintf (stderr, "*** %s ***\t", outs[l]);
    2747 #endif
    2748                             xmlChar *val =
    2749                               xmlGetProp (cur1, BAD_CAST outs[l]);
    2750                             if (val != NULL && strlen ((char *) val) > 0)
    2751                               {
    2752                                 if (tmpmaps->content != NULL)
    2753                                   addToMap (tmpmaps->content, outs[l],
    2754                                             (char *) val);
    2755                                 else
    2756                                   tmpmaps->content =
    2757                                     createMap (outs[l], (char *) val);
    2758                               }
    2759 #ifdef DEBUG
    2760                             fprintf (stderr, "%s\n", val);
    2761 #endif
    2762                             xmlFree (val);
    2763                           }
    2764                         xmlNodePtr cur2 = cur1->children;
    2765                         while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
    2766                           cur2 = cur2->next;
    2767                         while (cur2)
    2768                           {
    2769                 /**
    2770                  * Indentifier
     2580          {
     2581                addToMap (request_inputs, "ResponseDocument", "");
     2582                       
     2583                xmlNodePtr cur = tmps->nodeTab[0]; // only one ResponseDocument node
     2584                if (cur->type == XML_ELEMENT_NODE) {
     2585                /**
     2586                 * Get every attribute: storeExecuteResponse, lineage, status
    27712587                 */
    2772                             if (xmlStrncasecmp
    2773                                 (cur2->name, BAD_CAST "Identifier",
    2774                                  xmlStrlen (cur2->name)) == 0)
    2775                               {
    2776                                 xmlChar *val = xmlNodeListGetString (doc,
    2777                                                                      cur2->
    2778                                                                      xmlChildrenNode,
    2779                                                                      1);
    2780                                 if (tmpmaps == NULL)
    2781                                   {
    2782                                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2783                                     if (tmpmaps == NULL)
    2784                                       {
    2785                                         return errorException (m,
    2786                                                                _
    2787                                                                ("Unable to allocate memory."),
    2788                                                                "InternalError",
    2789                                                                NULL);
    2790                                       }
    2791                                     tmpmaps->name = zStrdup ((char *) val);
    2792                                     tmpmaps->content = NULL;
    2793                                     tmpmaps->next = NULL;
    2794                                   }
    2795                                 else
    2796                                   {
    2797                                     if (tmpmaps->name != NULL)
    2798                                       free (tmpmaps->name);
    2799                                     tmpmaps->name = zStrdup ((char *) val);;
    2800                                   }
    2801                                 xmlFree (val);
    2802                               }
    2803                 /**
    2804                  * Title, Asbtract
    2805                  */
    2806                             else
    2807                               if (xmlStrncasecmp
    2808                                   (cur2->name, BAD_CAST "Title",
    2809                                    xmlStrlen (cur2->name)) == 0
    2810                                   || xmlStrncasecmp (cur2->name,
    2811                                                      BAD_CAST "Abstract",
    2812                                                      xmlStrlen (cur2->name))
    2813                                   == 0)
    2814                               {
    2815                                 xmlChar *val = xmlNodeListGetString (doc,
    2816                                                                      cur2->
    2817                                                                      xmlChildrenNode,
    2818                                                                      1);
    2819                                 if (tmpmaps == NULL)
    2820                                   {
    2821                                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2822                                     if (tmpmaps == NULL)
    2823                                       {
    2824                                         return errorException (m,
    2825                                                                _
    2826                                                                ("Unable to allocate memory."),
    2827                                                                "InternalError",
    2828                                                                NULL);
    2829                                       }
    2830                                     tmpmaps->name =
    2831                                       zStrdup ("missingIndetifier");
    2832                                     tmpmaps->content =
    2833                                       createMap ((char *) cur2->name,
    2834                                                  (char *) val);
    2835                                     tmpmaps->next = NULL;
    2836                                   }
    2837                                 else
    2838                                   {
    2839                                     if (tmpmaps->content != NULL)
    2840                                       addToMap (tmpmaps->content,
    2841                                                 (char *) cur2->name,
    2842                                                 (char *) val);
    2843                                     else
    2844                                       tmpmaps->content =
    2845                                         createMap ((char *) cur2->name,
    2846                                                    (char *) val);
    2847                                   }
    2848                                 xmlFree (val);
    2849                               }
    2850                             cur2 = cur2->next;
    2851                             while (cur2 != NULL
    2852                                    && cur2->type != XML_ELEMENT_NODE)
    2853                               cur2 = cur2->next;
    2854                           }
    2855                       }
    2856                     cur1 = cur1->next;
    2857                     while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
    2858                       cur1 = cur1->next;
    2859                                  
    2860                                         if (request_output_real_format == NULL)
    2861                                           request_output_real_format = dupMaps (&tmpmaps);
    2862                                         else
    2863                                           addMapsToMaps (&request_output_real_format, tmpmaps);
    2864                   }
    2865               }
    2866           }
     2588                        //map* attributes = NULL;
     2589                        const char *ress[3] =
     2590                          { "storeExecuteResponse", "lineage", "status" };
     2591                        xmlChar *val;
     2592                        for (int l = 0; l < 3; l++)
     2593                        {
     2594        #ifdef DEBUG
     2595                                fprintf (stderr, "*** %s ***\t", ress[l]);
     2596        #endif
     2597                                val = xmlGetProp (cur, BAD_CAST ress[l]);
     2598                                if (val != NULL && strlen ((char *) val) > 0)
     2599                                {
     2600                                /*
     2601                                        if (attributes == NULL) {
     2602                                                attributes = createMap (ress[l], (char *) val);
     2603                                        }
     2604                                        else {
     2605                                                addToMap (attributes, ress[l], (char *) val);
     2606                                        }
     2607                                */             
     2608                                        addToMap (request_inputs, ress[l], (char *) val);
     2609                                  }
     2610        #ifdef DEBUG
     2611                                fprintf (stderr, "%s\n", val);
     2612        #endif
     2613                                xmlFree (val);
     2614                        }
     2615                       
     2616                        xmlNodePtr cur1 = cur->children;               
     2617                        while (cur1 != NULL) // iterate over Output nodes
     2618                        {
     2619                                if (cur1->type != XML_ELEMENT_NODE ||
     2620                                        xmlStrncasecmp(cur1->name, BAD_CAST "Output",
     2621                                                                   xmlStrlen (cur1->name)) != 0) {
     2622                                        cur1 = cur1->next;
     2623                                        continue;
     2624                                }
     2625                               
     2626                                maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node
     2627                                if (tmpmaps == NULL) {
     2628                                        return errorException (m,
     2629                                                                                   _
     2630                                                                                   ("Unable to allocate memory."),
     2631                                                                                   "InternalError", NULL);
     2632                                }
     2633                                tmpmaps->name = zStrdup ("unknownIdentifier");
     2634                                tmpmaps->content = NULL;
     2635                                tmpmaps->next = NULL;
     2636                               
     2637                                xmlNodePtr elems = cur1->children;
     2638                               
     2639                                while (elems != NULL) {
     2640                               
     2641                                        /**
     2642                                         * Identifier
     2643                                         */             
     2644                                        if (xmlStrncasecmp
     2645                                                (elems->name, BAD_CAST "Identifier",
     2646                                                 xmlStrlen (elems->name)) == 0)
     2647                                        {                       
     2648                                                xmlChar *val =
     2649                                                  xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
     2650                                               
     2651                                                free(tmpmaps->name);
     2652                                                tmpmaps->name = zStrdup ((char *) val); 
     2653                                                if (tmpmaps->content == NULL) {
     2654                                                        tmpmaps->content = createMap("Identifier", zStrdup ((char *) val));
     2655                                                }
     2656                                                else {
     2657                                                        addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val));
     2658                                                }
     2659                                         
     2660                                                map* tt = getMap (request_inputs, "ResponseDocument");                           
     2661                                                if (strlen(tt->value) == 0) {
     2662                                                  addToMap (request_inputs, "ResponseDocument",
     2663                                                                        (char *) val);                                                 
     2664                                                }       
     2665                                                else {
     2666                                                        char* tmp = (char*) malloc((strlen(tt->value) + 1
     2667                                                                                                + strlen((char*) val) + 1) * sizeof(char));
     2668                                                        sprintf (tmp, "%s;%s", tt->value, (char *) val);
     2669                                                        free(tt->value);
     2670                                                        tt->value = tmp;       
     2671                                                }       
     2672                                                xmlFree (val);
     2673                                        }                               
     2674                                        /**
     2675                                         * Title, Abstract
     2676                                         */
     2677                                        else if (xmlStrncasecmp(elems->name, BAD_CAST "Title",
     2678                                                                                        xmlStrlen (elems->name)) == 0
     2679                                                  || xmlStrncasecmp(elems->name, BAD_CAST "Abstract",
     2680                                                                                 xmlStrlen (elems->name)) == 0)
     2681                                        {
     2682                                                xmlChar *val =
     2683                                                        xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
     2684                                                       
     2685                                                if (tmpmaps->content == NULL) {
     2686                                                        tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val));
     2687                                                }
     2688                                                else {
     2689                                                        addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val));
     2690                                                }
     2691                                                xmlFree (val);
     2692                                        }
     2693                                        elems = elems->next;
     2694                                }
     2695                               
     2696                                /**
     2697                                 * Get every attribute from an Output node:
     2698                                 * mimeType, encoding, schema, uom, asReference
     2699                                 */
     2700                                const char *outs[5] =
     2701                                          { "mimeType", "encoding", "schema", "uom", "asReference" };
     2702                                         
     2703                                for (int l = 0; l < 5; l++) {
     2704        #ifdef DEBUG
     2705                                        fprintf (stderr, "*** %s ***\t", outs[l]);
     2706        #endif
     2707                                        xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]);                             
     2708                                        if (val != NULL && xmlStrlen(val) > 0) {
     2709                                                if (tmpmaps->content != NULL) {
     2710                                                        addToMap (tmpmaps->content, outs[l], (char *) val);
     2711                                                }                         
     2712                                                else {
     2713                                                        tmpmaps->content = createMap (outs[l], (char *) val);
     2714                                                }       
     2715                                        }
     2716        #ifdef DEBUG
     2717                                        fprintf (stderr, "%s\n", val);
     2718        #endif
     2719                                        xmlFree (val);
     2720                                }
     2721                               
     2722                                if (request_output_real_format == NULL) {
     2723                                        request_output_real_format = tmpmaps;
     2724                                }       
     2725                                else if (getMaps(request_output_real_format, tmpmaps->name) != NULL) {
     2726                                        return errorException (m,
     2727                                                                                   _
     2728                                                                                   ("Duplicate <Output> elements in WPS Execute request"),
     2729                                                                                   "InternalError", NULL);
     2730                                }
     2731                                else {
     2732                                        maps* mptr = request_output_real_format;
     2733                                        while (mptr->next != NULL) {
     2734                                                mptr = mptr->next;
     2735                                        }
     2736                                        mptr->next = tmpmaps;   
     2737                                }                                       
     2738                                cur1 = cur1->next;
     2739                        }                       
     2740                }
     2741          }
    28672742      xmlXPathFreeObject (tmpsptr);
    28682743      xmlFreeDoc (doc);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png