Changeset 790 for trunk/zoo-project


Ignore:
Timestamp:
Dec 19, 2016, 6:01:06 PM (7 years ago)
Author:
djay
Message:

Add support for nested inputs and outputs.

Location:
trunk/zoo-project
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/HISTORY.txt

    r784 r790  
    11Version 1.6.0-dev
     2  * Add nested inputs and outputs support (WPS 2.0.0)
    23  * Add servicePath special key to specify the service location
    34  * Add --with-etc-dir option to specify the location of the main.cfg file
  • trunk/zoo-project/zoo-kernel/caching.c

    r781 r790  
    148148
    149149/**
     150 * Read the downloaded file for a specific input
     151 *
     152 * @param m the maps containing the settings of the main.cfg file
     153 * @param in the input
     154 * @param index the input index
     155 * @param hInternet the internet connection
     156 * @return 0 in case of success, 4 in case of failure
     157 */
     158int readCurrentInput(maps** m,maps** in,int* index,HINTERNET* hInternet){
     159  map* tmp1;
     160  char sindex[5];
     161  maps* content=*in;
     162  map* length=getMap(content->content,"length");
     163  int shouldClean=-1;
     164  if(length==NULL){
     165    length=createMap("length","1");
     166    shouldClean=1;
     167  }
     168  for(int i=0;i<atoi(length->value);i++){
     169    char* fcontent;
     170    char *mimeType=NULL;
     171    int fsize=0;
     172    char cname[15];
     173    char vname[11];
     174    char vname1[11];
     175    char sname[9];
     176    char mname[15];
     177    char icname[14];
     178    char xname[16];
     179    char oname[12];
     180    if(*index>0)
     181      sprintf(vname1,"value_%d",*index);
     182    else
     183      sprintf(vname1,"value");
     184   
     185    if(i>0){
     186      tmp1=getMap(content->content,cname);
     187      sprintf(cname,"cache_file_%d",i);
     188      sprintf(vname,"value_%d",i);
     189      sprintf(sname,"size_%d",i);
     190      sprintf(mname,"mimeType_%d",i);
     191      sprintf(icname,"isCached_%d",i);
     192      sprintf(xname,"Reference_%d",i);
     193      sprintf(oname,"Order_%d",i);
     194    }else{
     195      sprintf(cname,"cache_file");
     196      sprintf(vname,"value");
     197      sprintf(sname,"size");
     198      sprintf(mname,"mimeType");
     199      sprintf(icname,"isCached");
     200      sprintf(xname,"Reference");
     201      sprintf(oname,"Order");
     202    }
     203   
     204    map* tmap=getMap(content->content,oname);
     205    sprintf(sindex,"%d",*index+1);
     206    if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
     207     
     208      if(getMap(content->content,icname)==NULL){
     209       
     210        fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char));
     211        if(fcontent == NULL){
     212          return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
     213        }
     214        size_t dwRead;
     215        InternetReadFile(hInternet->ihandle[*index],
     216                         (LPVOID)fcontent,
     217                         hInternet->ihandle[*index].nDataLen,
     218                         &dwRead);
     219        fcontent[hInternet->ihandle[*index].nDataLen]=0;
     220        fsize=hInternet->ihandle[*index].nDataLen;
     221        if(hInternet->ihandle[*index].mimeType==NULL)
     222          mimeType=zStrdup("none");
     223        else
     224          mimeType=zStrdup(hInternet->ihandle[*index].mimeType);             
     225       
     226        map* tmpMap=getMapOrFill(&(*in)->content,vname,"");
     227        free(tmpMap->value);
     228        tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
     229        if(tmpMap->value==NULL){
     230          return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
     231        }
     232        memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
     233       
     234        char ltmp1[256];
     235        sprintf(ltmp1,"%d",fsize);
     236        map* tmp=getMapFromMaps(*m,"main","cacheDir");
     237        if(tmp!=NULL){
     238          char* md5str=getMd5(tmp1->value);
     239          char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
     240          sprintf(fname,"%s/%s.zca",tmp->value,md5str);
     241          addToMap((*in)->content,cname,fname);
     242          free(fname);
     243        }
     244        addToMap((*in)->content,sname,ltmp1);
     245        addToMap((*in)->content,mname,mimeType);
     246        addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0);
     247        free(fcontent);
     248        free(mimeType);
     249        *index++;
     250       
     251      }
     252    }
     253  }
     254  if(shouldClean>0){
     255    freeMap(&length);
     256    free(length);
     257  }
     258  return 0;
     259}
     260
     261/**
    150262 * Effectively run all the HTTP requests in the queue
    151263 *
     
    157269 */
    158270int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){
    159   if(hInternet->nb>0){
     271  if(hInternet!=NULL && hInternet->nb>0){
    160272    processDownloads(hInternet);
    161273    maps* content=*inputs;
    162     map* tmp1;
    163274    int index=0;
    164     char sindex[5];
    165275    while(content!=NULL){
    166      
    167       map* length=getMap(content->content,"length");
    168       int shouldClean=-1;
    169       if(length==NULL){
    170         length=createMap("length","1");
    171         shouldClean=1;
    172       }
    173       for(int i=0;i<atoi(length->value);i++){
    174         char* fcontent;
    175         char *mimeType=NULL;
    176         int fsize=0;
    177         char cname[15];
    178         char vname[11];
    179         char vname1[11];
    180         char sname[9];
    181         char mname[15];
    182         char icname[14];
    183         char xname[16];
    184         char oname[12];
    185         if(index>0)
    186           sprintf(vname1,"value_%d",index);
    187         else
    188           sprintf(vname1,"value");
    189 
    190         if(i>0){
    191           tmp1=getMap(content->content,cname);
    192           sprintf(cname,"cache_file_%d",i);
    193           sprintf(vname,"value_%d",i);
    194           sprintf(sname,"size_%d",i);
    195           sprintf(mname,"mimeType_%d",i);
    196           sprintf(icname,"isCached_%d",i);
    197           sprintf(xname,"Reference_%d",i);
    198           sprintf(oname,"Order_%d",i);
    199         }else{
    200           sprintf(cname,"cache_file");
    201           sprintf(vname,"value");
    202           sprintf(sname,"size");
    203           sprintf(mname,"mimeType");
    204           sprintf(icname,"isCached");
    205           sprintf(xname,"Reference");
    206           sprintf(oname,"Order");
    207         }
    208 
    209         map* tmap=getMap(content->content,oname);
    210         sprintf(sindex,"%d",index+1);
    211         if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
    212 
    213           if(getMap(content->content,icname)==NULL){
    214            
    215             fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
    216             if(fcontent == NULL){
    217               return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
    218             }
    219             size_t dwRead;
    220             InternetReadFile(hInternet->ihandle[index],
    221                              (LPVOID)fcontent,
    222                              hInternet->ihandle[index].nDataLen,
    223                              &dwRead);
    224             fcontent[hInternet->ihandle[index].nDataLen]=0;
    225             fsize=hInternet->ihandle[index].nDataLen;
    226             if(hInternet->ihandle[index].mimeType==NULL)
    227               mimeType=strdup("none");
    228             else
    229               mimeType=strdup(hInternet->ihandle[index].mimeType);           
    230            
    231             map* tmpMap=getMapOrFill(&content->content,vname,"");
    232             free(tmpMap->value);
    233             tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    234             if(tmpMap->value==NULL){
    235               return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
    236             }
    237             memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
    238            
    239             char ltmp1[256];
    240             sprintf(ltmp1,"%d",fsize);
    241             map* tmp=getMapFromMaps(*m,"main","cacheDir");
    242             if(tmp!=NULL){
    243               char* md5str=getMd5(tmp1->value);
    244               char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
    245               sprintf(fname,"%s/%s.zca",tmp->value,md5str);
    246               addToMap(content->content,cname,fname);
    247               free(fname);
    248             }
    249             addToMap(content->content,sname,ltmp1);
    250             addToMap(content->content,mname,mimeType);
    251             addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0);
    252             free(fcontent);
    253             free(mimeType);
    254             index++;
    255 
    256           }
     276      if(content->child!=NULL){
     277        maps* cursor=content->child;
     278        while(cursor!=NULL){
     279          readCurrentInput(m,&cursor,&index,hInternet);
     280          cursor=cursor->next;
    257281        }
    258282      }
    259       if(shouldClean>0){
    260         freeMap(&length);
    261         free(length);
    262       }
    263      
     283      else
     284        readCurrentInput(m,&content,&index,hInternet);
    264285      content=content->next;
    265     }
    266    
     286    }
    267287  }
    268288  return 0;
     
    281301  maps *oreq=getMaps(*m,"orequests");
    282302  if(oreq==NULL){
    283     oreq=(maps*)malloc(MAPS_SIZE);
    284     oreq->name=zStrdup("orequests");
     303    oreq=createMaps("orequests");
    285304    oreq->content=createMap("value",url);
    286     oreq->next=NULL;
    287305    addMapsToMaps(m,oreq);
    288306    freeMaps(&oreq);
     
    351369   
    352370  free(tmpMap->value);
    353 
    354371  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    355372  if(tmpMap->value==NULL || fcontent == NULL)
  • trunk/zoo-project/zoo-kernel/main_conf_read.y

    r781 r790  
    111111     free(current_content);
    112112     current_maps->next=NULL;
    113      current_maps->next=(maps*)malloc(MAPS_SIZE);
    114      current_maps->next->name=zStrdup($1);
    115      current_maps->next->content=NULL;
    116      current_maps->next->next=NULL;
     113     current_maps->next=createMaps($1);
    117114     current_maps=current_maps->next;
    118115     current_content=current_maps->content;
  • trunk/zoo-project/zoo-kernel/request_parser.c

    r781 r790  
    6060  map *tmap = getMapType (tmpMaps->content);
    6161  elements *el = getElements (elem, mi->name);
     62  elements *cursor = elem;
     63  while(cursor!=NULL && el==NULL){
     64    if(cursor->child!=NULL)
     65      el = getElements (cursor->child, mi->name);
     66    cursor=cursor->next;
     67  }
    6268  int hasEl = 1;
    6369  if (el == NULL)
    6470    hasEl = -1;
     71
    6572  if (tmap == NULL)
    6673    {
     
    178185      }
    179186    }
     187    if(cursor->child!=NULL)
     188      ensureDecodedBase64(&cursor->child);
    180189    cursor=cursor->next;
    181190  }
     
    255264            if (tmpmaps == NULL)
    256265              {
    257                 tmpmaps = (maps *) malloc (MAPS_SIZE);
     266                tmpmaps = createMaps(tmpn);
    258267                if (tmpmaps == NULL)
    259268                  {
     
    263272                                           "InternalError", NULL);
    264273                  }
    265                 tmpmaps->name = zStrdup (tmpn);
    266274                if (tmpv != NULL)
    267275                  {
     
    433441                  if (tmp_output == NULL)
    434442                    {
    435                       tmp_output = (maps *) malloc (MAPS_SIZE);
     443                      tmp_output = createMaps(tmpc);
    436444                      if (tmp_output == NULL)
    437445                        {
     
    442450                                                 "InternalError", NULL);
    443451                        }
    444                       tmp_output->name = zStrdup (tmpc);
    445                       tmp_output->content = NULL;
    446                       tmp_output->next = NULL;
    447452                    }
    448453                }
     
    491496int defineMissingIdentifier(maps** main_conf,maps** mymaps){
    492497  if (*mymaps == NULL){
    493     *mymaps = (maps *) malloc (MAPS_SIZE);
     498    *mymaps = createMaps("missingIndetifier");
    494499    if (*mymaps == NULL){
    495500      return errorException (*main_conf,
     
    497502                             "InternalError", NULL);
    498503    }
    499     (*mymaps)->name = zStrdup ("missingIndetifier");
    500     (*mymaps)->content = NULL;
    501     (*mymaps)->next = NULL;
    502504  }
    503505  return 0;
     
    529531          // A specific Input node.
    530532          if(vid==1){
    531             tmpmaps = (maps *) malloc (MAPS_SIZE);
    532533            xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
    533             tmpmaps->name = zStrdup ((char *) val);
    534             tmpmaps->content = NULL;
    535             tmpmaps->next = NULL;
     534            tmpmaps = createMaps((char *) val);
    536535          }
    537536
     
    552551                  if (tmpmaps == NULL && val!=NULL)
    553552                    {
    554                       tmpmaps = (maps *) malloc (MAPS_SIZE);
     553                      tmpmaps = createMaps((char*)val);
    555554                      if (tmpmaps == NULL)
    556555                        {
     
    560559                                                 "InternalError", NULL);
    561560                        }
    562                       tmpmaps->name = zStrdup ((char *) val);
    563                       tmpmaps->content = NULL;
    564                       tmpmaps->next = NULL;
    565561                      xmlFree (val);
    566562                    }
     
    586582                  }
    587583                }
    588               // InputDataFormChoice (Reference or Data ?)
    589               if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0)
     584              // InputDataFormChoice (Reference or Data ?) / 2.0.0 DataInputType / Input
     585              if (xmlStrcasecmp (cur2->name, BAD_CAST "Input") == 0)
     586                {
     587                  char *xpathExpr=(char*)malloc(61+strlen(tmpmaps->name));
     588                  sprintf(xpathExpr,"/*/*[local-name()='Input' and @id='%s']/*[local-name()='Input']",tmpmaps->name);
     589                  xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr);
     590                  xmlNodeSet *tmps = tmpsptr->nodesetval;
     591                  if(tmps!=NULL){
     592                    maps* request_output1=NULL;
     593                    if(xmlParseInputs(main_conf,s,&request_output1,doc,tmps,hInternet)<0)
     594                      return -1;
     595                    if(tmpmaps->child==NULL)
     596                      tmpmaps->child=dupMaps(&request_output1);
     597                    else
     598                      addMapsToMaps(&tmpmaps->child,request_output1);
     599                    freeMaps(&request_output1);
     600                    free(request_output1);
     601                  }
     602                  while(cur2->next!=NULL)
     603                    cur2=cur2->next;
     604                }
     605              else if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0)
    590606                {
    591607                  defineMissingIdentifier(main_conf,&tmpmaps);
     
    848864                        cur4=cur4->next;
    849865                      if(cur4!=NULL){
    850                         if(cur4->content!=NULL)
     866                        if(cur4->content!=NULL){
    851867                          if (tmpmaps->content != NULL)
    852868                            addToMap (tmpmaps->content, "value",
     
    855871                            tmpmaps->content =
    856872                              createMap ("value", (char *) cur4->content);
     873                        }
    857874                        cur4=cur4->next;
    858875                      }
     
    955972                                     && cur5->type != XML_CDATA_SECTION_NODE)
    956973                                cur5 = cur5->next;
    957                               fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    958                               fflush(stderr);
    959974                              if (cur5 != NULL
    960975                                  && cur5->type != XML_CDATA_SECTION_NODE)
     
    10181033          {
    10191034            map* test=getMap(tmpmaps->content,"value");
    1020             if(test==NULL)
     1035            if(test==NULL && tmpmaps->child==NULL)
    10211036              addToMap(tmpmaps->content,"value","");
    1022             maps *testPresence =
    1023               getMaps (*request_output, tmpmaps->name);
     1037            maps *testPresence = getMaps (*request_output, tmpmaps->name);
     1038            maps *cursor=*request_output;
     1039            while(testPresence == NULL && cursor!=NULL){
     1040              if(cursor->child!=NULL){
     1041                testPresence = getMaps (cursor->child, tmpmaps->name);
     1042              }
     1043              cursor=cursor->next;
     1044            }
    10241045            if (testPresence != NULL)
    10251046              {
    10261047                elements *elem = getElements (s->inputs, tmpmaps->name);
     1048                elements *cursor=s->inputs;
     1049                while(elem == NULL && cursor!=NULL){
     1050                  if(cursor->child!=NULL){
     1051                    elem = getElements (cursor->child, tmpmaps->name);
     1052                  }
     1053                  cursor=cursor->next;
     1054                }
    10271055                if (elem != NULL)
    10281056                  {
    10291057                    if (appendMapsToMaps
    1030                         (*main_conf, *request_output, tmpmaps, elem) < 0)
     1058                        (*main_conf, testPresence, tmpmaps, elem) < 0)
    10311059                      {
    10321060                        return errorException (*main_conf,
     
    10661094    xmlNodePtr cur = nodes->nodeTab[k];
    10671095    if (cur->type == XML_ELEMENT_NODE){
    1068       maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
     1096      maps *tmpmaps = NULL;
    10691097      xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
    10701098      if(val!=NULL)
    1071         tmpmaps->name = zStrdup ((char*)val);
     1099        tmpmaps = createMaps((char *)val);
    10721100      else
    1073         tmpmaps->name = zStrdup ("unknownIdentifier");
    1074       tmpmaps->content = NULL;
    1075       tmpmaps->next = NULL;
     1101        tmpmaps = createMaps("unknownIdentifier");
    10761102      const char ress[4][13] =
    10771103        { "mimeType", "encoding", "schema", "transmission" };
     
    10911117        xmlFree (val);
    10921118      }
    1093       if (*request_output == NULL)
     1119      if(cur->children!=NULL){
     1120        xmlNodePtr ccur = cur->children;
     1121        while (ccur != NULL){
     1122          if(ccur->type == XML_ELEMENT_NODE){
     1123            char *xpathExpr=(char*)malloc(65+strlen(tmpmaps->name));
     1124            sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name);
     1125            xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr);
     1126            xmlNodeSet* cnodes = tmpsptr->nodesetval;
     1127            xmlParseOutputs2(main_conf,request_inputs,&tmpmaps->child,doc,cnodes);
     1128            break;
     1129          }
     1130          ccur = ccur->next;
     1131        }
     1132      }
     1133      if (*request_output == NULL){
    10941134        *request_output = dupMaps(&tmpmaps);
    1095       else
     1135      }
     1136      else{
    10961137        addMapsToMaps(request_output,tmpmaps);
     1138      }
     1139      freeMaps(&tmpmaps);
     1140      free(tmpmaps);
    10971141    }
    10981142  }
     
    11191163        {
    11201164
    1121           maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
     1165          maps *tmpmaps = createMaps("unknownIdentifier");
    11221166          if (tmpmaps == NULL)
    11231167            {
     
    11251169                                     "InternalError", NULL);
    11261170            }
    1127           tmpmaps->name = zStrdup ("unknownIdentifier");
    1128           tmpmaps->content = NULL;
    1129           tmpmaps->next = NULL;
    11301171
    11311172          // Get every attribute from a RawDataOutput node
     
    12101251            }
    12111252                               
    1212             maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node
     1253            maps *tmpmaps = createMaps("unknownIdentifier"); // one per Output node
    12131254            if (tmpmaps == NULL) {
    12141255              return errorException (*main_conf,
     
    12171258                                     "InternalError", NULL);
    12181259            }
    1219             tmpmaps->name = zStrdup ("unknownIdentifier");
    1220             tmpmaps->content = NULL;
    1221             tmpmaps->next = NULL;
    12221260                               
    12231261            xmlNodePtr elems = cur1->children;
     
    15131551  char *dfv1 =
    15141552    addDefaultValues (request_outputs, s->outputs, *main_conf, 1,&errO);
     1553
    15151554  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
    15161555    {
  • trunk/zoo-project/zoo-kernel/response_print.c

    r788 r790  
    14891489   
    14901490      xmlAddChild(nc2,nc3);
     1491    }else{
     1492      if(e->child!=NULL && vid!=0){
     1493        printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid);
     1494      }
    14911495    }
    14921496   
    1493     xmlAddChild(nc1,nc2);
     1497    if(e->child!=NULL && vid==0){
     1498      elements* children=dupElements(e->child);
     1499      elements* cursor=children;
     1500      while(cursor!=NULL){
     1501        char* tmp=strdup(cursor->name);
     1502        free(cursor->name);
     1503        cursor->name=(char*)malloc((strlen(cursor->name)+strlen(e->name)+2)*sizeof(char));
     1504        sprintf(cursor->name,"%s.%s",e->name,tmp);
     1505        cursor=cursor->next;
     1506      }
     1507      printFullDescription(in,children,type,ns,ns_ows,nc2,vid);
     1508      xmlAddChild(nc1,nc2);
     1509      freeElements(&children);
     1510      free(children);
     1511    }else
     1512      xmlAddChild(nc1,nc2);
    14941513   
    14951514    e=e->next;
     
    19581977  }
    19591978
    1960   /**
    1961    * IO type Reference or full Data ?
    1962    */
    1963   map *tmpMap=getMap(m->content,"Reference");
    1964   if(tmpMap==NULL){
    1965     nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
    1966     if(e!=NULL && e->format!=NULL){
    1967       if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
    1968         nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     1979  // IO type nested outputs
     1980  if(m->child!=NULL){
     1981    maps* curs=m->child;
     1982    elements* ecurs=getElements(e,(e!=NULL?e->name:m->name));
     1983    ecurs=ecurs->child;
     1984    while(curs!=NULL && ecurs!=NULL){
     1985      map* inRequest=getMap(curs->content,"inRequest");
     1986      if(inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0)
     1987        printIOType(doc,nc1,ns_wps,ns_ows,ns_xlink,ecurs,curs,type,vid);
     1988      curs=curs->next;
     1989      ecurs=ecurs->next;
     1990    }
     1991  }
     1992  else{
     1993    map *tmpMap=getMap(m->content,"Reference");
     1994    if(tmpMap==NULL){
     1995      nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
     1996      if(e!=NULL && e->format!=NULL){
     1997        if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
     1998          nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     1999        else
     2000          if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
     2001            nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
     2002          else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
     2003            nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
     2004          else
     2005            nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
     2006      }
     2007      else {
     2008        map* tmpV=getMapFromMaps(m,"format","value");
     2009        if(tmpV!=NULL)
     2010          nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
     2011        else
     2012          nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     2013      }
     2014      tmp=m->content;
     2015     
     2016      while(tmp!=NULL){
     2017        if(strcasecmp(tmp->name,"mimeType")==0 ||
     2018           strcasecmp(tmp->name,"encoding")==0 ||
     2019           strcasecmp(tmp->name,"schema")==0 ||
     2020           strcasecmp(tmp->name,"datatype")==0 ||
     2021           strcasecmp(tmp->name,"uom")==0) {
     2022         
     2023          if(vid==0)
     2024            xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
     2025          else{
     2026            if(strcasecmp(tmp->name,"datatype")==0)
     2027              xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain");
     2028            else
     2029              if(strcasecmp(tmp->name,"uom")!=0)
     2030                xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value);
     2031          }
     2032        }
     2033        if(vid==0)
     2034          xmlAddChild(nc2,nc3);
     2035        tmp=tmp->next;
     2036      }
     2037      if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
     2038        map* bb=getMap(m->content,"value");
     2039        if(bb!=NULL) {
     2040          map* tmpRes=parseBoundingBox(bb->value);
     2041          printBoundingBox(ns_ows,nc3,tmpRes);
     2042          freeMap(&tmpRes);
     2043          free(tmpRes);
     2044        }
     2045      }
     2046      else {
     2047        if(e!=NULL)
     2048          tmp=getMap(e->defaults->content,"mimeType");
     2049        else
     2050          tmp=NULL;
     2051       
     2052        map* tmp1=getMap(m->content,"encoding");
     2053        map* tmp2=getMap(m->content,"mimeType");
     2054        map* tmp3=getMap(m->content,"value");
     2055        int hasValue=1;
     2056        if(tmp3==NULL){
     2057          tmp3=createMap("value","");
     2058          hasValue=-1;
     2059        }
     2060       
     2061        if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
     2062            ||                                                         // or if
     2063            ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text
     2064                                &&                                       //  nor
     2065                                strstr(tmp2->value,"xml") == NULL        //  xml
     2066                                &&                                       // nor
     2067                                strstr(tmp2->value,"javascript") == NULL // javascript
     2068                                &&
     2069                                strstr(tmp2->value,"json") == NULL
     2070                                &&
     2071                                strstr(tmp2->value,"ecmascript") == NULL
     2072                                &&
     2073                                // include for backwards compatibility,
     2074                                // although correct mime type is ...kml+xml:
     2075                                strstr(tmp2->value,"google-earth.kml") == NULL                                                  )
     2076              )
     2077            ) {                                                          // then       
     2078          map* rs=getMap(m->content,"size");                       // obtain size
     2079          bool isSized=true;
     2080          if(rs==NULL){
     2081            char tmp1[1024];
     2082            sprintf(tmp1,"%ld",strlen(tmp3->value));
     2083            rs=createMap("size",tmp1);
     2084            isSized=false;
     2085          }
     2086         
     2087          xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
     2088         
     2089          if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
     2090            xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding");
     2091            if (ap != NULL) {
     2092              xmlRemoveProp(ap);
     2093            }                   
     2094            xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64");
     2095          }
     2096         
     2097          if(!isSized){
     2098            freeMap(&rs);
     2099            free(rs);
     2100          }
     2101        }
     2102        else if (tmp2!=NULL) {                                 // else (text-based format)
     2103          if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block
     2104             strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
     2105             strstr(tmp2->value, "ecmascript") != NULL
     2106           ) {
     2107            xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
     2108          }   
     2109          else {                                                     // else
     2110            if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
     2111                // include for backwards compatibility,
     2112              // although correct mime type is ...kml+xml:                 
     2113                strstr(tmp2->value, "google-earth.kml") != NULL
     2114                ) {
     2115             
     2116              int li=zooXmlAddDoc(tmp3->value);
     2117              xmlDocPtr doc = iDocs[li];
     2118              xmlNodePtr ir = xmlDocGetRootElement(doc);
     2119              xmlAddChild((vid==0?nc3:nc2),ir);
     2120            }
     2121            else                                                     // else   
     2122              xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));    //   add text node
     2123          }
     2124          xmlAddChild(nc2,nc3);
     2125        }
     2126        else {
     2127          xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));
     2128        }
     2129       
     2130        if(hasValue<0) {
     2131          freeMap(&tmp3);
     2132          free(tmp3);
     2133        }
     2134      }
     2135    }
     2136    else { // Reference
     2137      tmpMap=getMap(m->content,"Reference");
     2138      nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
     2139      /* Special case to avoid failing to validate against the WPS 2.0 schema */
     2140      if(strcasecmp(type,"Output")==0 && vid==0)
     2141        xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
    19692142      else
    1970         if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
    1971           nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
    1972         else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
    1973           nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
    1974         else
    1975           nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
    1976     }
    1977     else {
    1978       map* tmpV=getMapFromMaps(m,"format","value");
    1979       if(tmpV!=NULL)
    1980         nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
    1981       else
    1982         nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
    1983     }
    1984     tmp=m->content;
    1985 
    1986     while(tmp!=NULL){
    1987       if(strcasecmp(tmp->name,"mimeType")==0 ||
    1988          strcasecmp(tmp->name,"encoding")==0 ||
    1989          strcasecmp(tmp->name,"schema")==0 ||
    1990          strcasecmp(tmp->name,"datatype")==0 ||
    1991          strcasecmp(tmp->name,"uom")==0) {
    1992        
    1993         if(vid==0)
    1994           xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
    1995         else{
     2143        xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
     2144     
     2145      tmp=m->content;
     2146      while(tmp!=NULL) {
     2147        if(strcasecmp(tmp->name,"mimeType")==0 ||
     2148           strcasecmp(tmp->name,"encoding")==0 ||
     2149           strcasecmp(tmp->name,"schema")==0 ||
     2150           strcasecmp(tmp->name,"datatype")==0 ||
     2151           strcasecmp(tmp->name,"uom")==0){
     2152         
    19962153          if(strcasecmp(tmp->name,"datatype")==0)
    1997             xmlNewProp(nc2,BAD_CAST "mimeType",BAD_CAST "text/plain");
     2154            xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
    19982155          else
    1999             if(strcasecmp(tmp->name,"uom")!=0)
    2000               xmlNewProp(nc2,BAD_CAST tmp->name,BAD_CAST tmp->value);
    2001         }
    2002       }
    2003       if(vid==0)
     2156            xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
     2157        }
     2158        tmp=tmp->next;
    20042159        xmlAddChild(nc2,nc3);
    2005       tmp=tmp->next;
    2006     }
    2007     if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
    2008       map* bb=getMap(m->content,"value");
    2009       if(bb!=NULL) {
    2010         map* tmpRes=parseBoundingBox(bb->value);
    2011         printBoundingBox(ns_ows,nc3,tmpRes);
    2012         freeMap(&tmpRes);
    2013         free(tmpRes);
    2014       }
    2015     }
    2016     else {
    2017       if(e!=NULL)
    2018         tmp=getMap(e->defaults->content,"mimeType");
    2019       else
    2020         tmp=NULL;
    2021        
    2022       map* tmp1=getMap(m->content,"encoding");
    2023       map* tmp2=getMap(m->content,"mimeType");
    2024       map* tmp3=getMap(m->content,"value");
    2025       int hasValue=1;
    2026       if(tmp3==NULL){
    2027         tmp3=createMap("value","");
    2028         hasValue=-1;
    2029       }
    2030 
    2031       if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
    2032           ||                                                           // or if
    2033           ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text
    2034                               &&                                       //  nor
    2035                               strstr(tmp2->value,"xml") == NULL        //  xml
    2036                               &&                                       // nor
    2037                               strstr(tmp2->value,"javascript") == NULL // javascript
    2038                               &&
    2039                               strstr(tmp2->value,"json") == NULL
    2040                               &&
    2041                               strstr(tmp2->value,"ecmascript") == NULL
    2042                               &&
    2043                               // include for backwards compatibility,
    2044                               // although correct mime type is ...kml+xml:
    2045                               strstr(tmp2->value,"google-earth.kml") == NULL                                                    )
    2046             )
    2047           ) {                                                    // then       
    2048         map* rs=getMap(m->content,"size");                       // obtain size
    2049         bool isSized=true;
    2050         if(rs==NULL){
    2051           char tmp1[1024];
    2052           sprintf(tmp1,"%ld",strlen(tmp3->value));
    2053           rs=createMap("size",tmp1);
    2054           isSized=false;
    2055         }
    2056          
    2057         xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
    2058                
    2059         if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
    2060           xmlAttrPtr ap = xmlHasProp((vid==0?nc3:nc2), BAD_CAST "encoding");
    2061           if (ap != NULL) {
    2062             xmlRemoveProp(ap);
    2063           }                     
    2064           xmlNewProp((vid==0?nc3:nc2),BAD_CAST "encoding",BAD_CAST "base64");
    2065         }
    2066                
    2067         if(!isSized){
    2068           freeMap(&rs);
    2069           free(rs);
    2070         }
    2071       }
    2072       else if (tmp2!=NULL) {                                 // else (text-based format)
    2073         if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block
    2074            strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader)
    2075            strstr(tmp2->value, "ecmascript") != NULL
    2076            ) {
    2077           xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
    2078         }   
    2079         else {                                                     // else
    2080           if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
    2081               // include for backwards compatibility,
    2082               // although correct mime type is ...kml+xml:                 
    2083               strstr(tmp2->value, "google-earth.kml") != NULL
    2084               ) {
    2085                          
    2086             int li=zooXmlAddDoc(tmp3->value);
    2087             xmlDocPtr doc = iDocs[li];
    2088             xmlNodePtr ir = xmlDocGetRootElement(doc);
    2089             xmlAddChild((vid==0?nc3:nc2),ir);
    2090           }
    2091           else                                                     // else     
    2092             xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));    //   add text node
    2093         }
    2094         xmlAddChild(nc2,nc3);
    2095       }
    2096       else {
    2097         xmlAddChild((vid==0?nc3:nc2),xmlNewText(BAD_CAST tmp3->value));
    2098       }
    2099          
    2100       if(hasValue<0) {
    2101         freeMap(&tmp3);
    2102         free(tmp3);
    2103       }
    2104     }
    2105   }
    2106   else { // Reference
    2107     tmpMap=getMap(m->content,"Reference");
    2108     nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
    2109     if(strcasecmp(type,"Output")==0)
    2110       xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
    2111     else
    2112       xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
    2113    
    2114     tmp=m->content;
    2115     while(tmp!=NULL) {
    2116       if(strcasecmp(tmp->name,"mimeType")==0 ||
    2117          strcasecmp(tmp->name,"encoding")==0 ||
    2118          strcasecmp(tmp->name,"schema")==0 ||
    2119          strcasecmp(tmp->name,"datatype")==0 ||
    2120          strcasecmp(tmp->name,"uom")==0){
    2121 
    2122         if(strcasecmp(tmp->name,"datatype")==0)
    2123           xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
    2124         else
    2125           xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
    2126       }
    2127       tmp=tmp->next;
    2128       xmlAddChild(nc2,nc3);
    2129     }
    2130   }
    2131   xmlAddChild(nc1,nc2);
     2160      }
     2161    }
     2162    xmlAddChild(nc1,nc2);
     2163  }
    21322164  xmlAddChild(nc,nc1);
    21332165}
     
    23942426      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
    23952427      errorException(m,tmpMsg,"InternalError",NULL);
    2396 
    23972428      return;
    23982429    }
     
    24372468#endif
    24382469    maps* tmpI=request_outputs;
     2470    maps* stmpI=NULL;
    24392471    map* usid=getMapFromMaps(m,"lenv","usid");
    24402472    int itn=0;
     2473  NESTED0:
    24412474    while(tmpI!=NULL){
     2475      if(tmpI->child!=NULL){
     2476        stmpI=tmpI;
     2477        tmpI=tmpI->child;
     2478      }
    24422479#ifdef USE_MS
    24432480      map* testMap=getMap(tmpI->content,"useMapserver");       
     
    24622499        {
    24632500          elements* in=getElements(s->outputs,tmpI->name);
     2501          if(in==NULL && s->outputs->child!=NULL){
     2502            in=getElements(s->outputs->child,tmpI->name);
     2503          }
    24642504          char *format=NULL;
    24652505          if(in!=NULL && in->format!=NULL){
     
    25452585#endif
    25462586      tmpI=tmpI->next;
     2587    }
     2588    if(stmpI!=NULL){
     2589      tmpI=stmpI->next;
     2590      stmpI=NULL;
     2591      if(tmpI!=NULL)
     2592        goto NESTED0;
    25472593    }
    25482594#ifdef DEBUG
  • trunk/zoo-project/zoo-kernel/server_internal.c

    r789 r790  
    583583  map *res=*err;
    584584  elements* tmpInputs=in;
     585  elements* tmpInputss=NULL;
    585586  maps* out1=*out;
     587  maps* out1s=NULL;
    586588  char *result=NULL;
    587589  int nb=0;
     590  int inb=0;
     591 loopOnInputs:
    588592  if(type==1){
    589593    while(out1!=NULL){
     
    597601        result=out1->name;
    598602      }
     603      inb++;
    599604      out1=out1->next;
    600605    }
    601606    if(res!=NULL){
     607      fflush(stderr);
    602608      *err=res;
    603609      return result;
    604610    }
    605     out1=*out;
     611    if(out1==NULL && inb>=1)
     612      out1=*out;
    606613  }
    607614  while(tmpInputs!=NULL){
    608615    maps *tmpMaps=getMaps(out1,tmpInputs->name);
    609616    if(tmpMaps==NULL){
    610       maps* tmpMaps2=(maps*)malloc(MAPS_SIZE);
    611       tmpMaps2->name=strdup(tmpInputs->name);
    612       tmpMaps2->content=NULL;
    613       tmpMaps2->next=NULL;
    614      
     617      maps* tmpMaps2=createMaps(tmpInputs->name);
    615618      if(type==0){
    616619        map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs");
     
    651654        }
    652655      }
    653 
     656     
    654657      if(res==NULL){
    655658        iotype* tmpIoType=tmpInputs->defaults;
     
    685688    }
    686689    else{
    687       iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,
    688                                              tmpMaps->content);
    689       if(type==0) {
    690         /**
    691          * In case of an Input maps, then add the minOccurs and maxOccurs to the
    692          * content map.
    693          */
    694         map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
    695         if(tmpMap1!=NULL){
    696           if(tmpMaps->content==NULL)
    697             tmpMaps->content=createMap("minOccurs",tmpMap1->value);
    698           else
    699             addToMap(tmpMaps->content,"minOccurs",tmpMap1->value);
    700         }
    701         map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
    702         if(tmpMaxO!=NULL){
    703           if(tmpMaps->content==NULL)
    704             tmpMaps->content=createMap("maxOccurs",tmpMaxO->value);
    705           else
    706             addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value);
    707         }
    708         map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
    709         if(tmpMaxMB!=NULL){
    710           if(tmpMaps->content==NULL)
    711             tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
    712           else
    713             addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
    714         }
    715         /**
    716          * Parsing BoundingBoxData, fill the following map and then add it to
    717          * the content map of the Input maps:
    718          * lowerCorner, upperCorner, srs and dimensions
    719          * cf. parseBoundingBox
    720          */
    721         if(tmpInputs->format!=NULL && strcasecmp(tmpInputs->format,"BoundingBoxData")==0){
    722           maps* tmpI=getMaps(*out,tmpInputs->name);
    723           if(tmpI!=NULL){
    724             map* tmpV=getMap(tmpI->content,"value");
    725             if(tmpV!=NULL){
    726               char *tmpVS=strdup(tmpV->value);
    727               map* tmp=parseBoundingBox(tmpVS);
    728               free(tmpVS);
    729               map* tmpC=tmp;
    730               while(tmpC!=NULL){
    731                 addToMap(tmpMaps->content,tmpC->name,tmpC->value);
    732                 tmpC=tmpC->next;
     690      iotype* tmpIoType=NULL;
     691      if(tmpMaps->content!=NULL){
     692        tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,
     693                                       tmpMaps->content);
     694        if(type==0) {
     695          /**
     696           * In case of an Input maps, then add the minOccurs and maxOccurs to the
     697           * content map.
     698           */
     699          map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
     700          if(tmpMap1!=NULL){
     701            if(tmpMaps->content==NULL)
     702              tmpMaps->content=createMap("minOccurs",tmpMap1->value);
     703            else
     704              addToMap(tmpMaps->content,"minOccurs",tmpMap1->value);
     705          }
     706          map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
     707          if(tmpMaxO!=NULL){
     708            if(tmpMaps->content==NULL)
     709              tmpMaps->content=createMap("maxOccurs",tmpMaxO->value);
     710            else
     711              addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value);
     712          }
     713          map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
     714          if(tmpMaxMB!=NULL){
     715            if(tmpMaps->content==NULL)
     716              tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
     717            else
     718              addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
     719          }
     720          /**
     721           * Parsing BoundingBoxData, fill the following map and then add it to
     722           * the content map of the Input maps:
     723           * lowerCorner, upperCorner, srs and dimensions
     724           * cf. parseBoundingBox
     725           */
     726          if(tmpInputs->format!=NULL && strcasecmp(tmpInputs->format,"BoundingBoxData")==0){
     727            maps* tmpI=getMaps(*out,tmpInputs->name);
     728            if(tmpI!=NULL){
     729              map* tmpV=getMap(tmpI->content,"value");
     730              if(tmpV!=NULL){
     731                char *tmpVS=strdup(tmpV->value);
     732                map* tmp=parseBoundingBox(tmpVS);
     733                free(tmpVS);
     734                map* tmpC=tmp;
     735                while(tmpC!=NULL){
     736                  addToMap(tmpMaps->content,tmpC->name,tmpC->value);
     737                  tmpC=tmpC->next;
     738                }
     739                freeMap(&tmp);
     740                free(tmp);
    733741              }
    734               freeMap(&tmp);
    735               free(tmp);
    736742            }
    737743          }
     744        }
     745      }else{
     746        if(tmpInputs!=NULL){
     747          tmpIoType=tmpInputs->defaults;
    738748        }
    739749      }
     
    807817      else
    808818        addToMap(tmpMaps->content,"inRequest","true");
    809 
    810     }
    811     tmpInputs=tmpInputs->next;
     819      elements* tmpElements=getElements(in,tmpMaps->name);
     820      if(tmpMaps->child!=NULL and tmpElements!=NULL and tmpElements->child!=NULL){
     821        char *res=addDefaultValues(&tmpMaps->child,tmpElements->child,m,type,err);
     822        if(strlen(res)>0){
     823          fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     824          return res;
     825        }
     826      }
     827    }
     828    if(tmpInputs->child!=NULL){
     829      tmpInputss=tmpInputs->next;
     830      tmpInputs=tmpInputs->child;
     831      if(tmpMaps!=NULL){
     832        out1=tmpMaps->child;
     833        out1s=tmpMaps;
     834      }
     835    }else
     836      tmpInputs=tmpInputs->next;
     837  }
     838  if(tmpInputss!=NULL){
     839    out1=out1s;
     840    tmpInputs=tmpInputss;
     841    tmpInputss=NULL;
     842    out1s=NULL;
     843    goto loopOnInputs;
    812844  }
    813845  if(res!=NULL){
     
    879911      maps *res = (maps *) malloc (MAPS_SIZE);
    880912      conf_read (fbkpid, res);
     913      res->child=NULL;
    881914      map* status=getMapFromMaps(res,"status","status");
    882915      addToMap(statusInfo,"Status",status->value);
  • trunk/zoo-project/zoo-kernel/service.c

    r757 r790  
    7474
    7575/**
    76  * Dump a map to a file
     76 * Dump a map to a file 
    7777 *
    7878 * @param t the map to dump to file
    79  * @param file the file to store the map
     79 * @param file the file pointer to store the map
    8080 */
    8181void dumpMapToFile(map* t,FILE* file){
     
    9696  while(tmp!=NULL){
    9797    fprintf(stderr,"MAP => [%s] \n",tmp->name);
     98    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
    9899    dumpMap(tmp->content);
     100    fprintf(stderr," * CHILD [%s] \n",tmp->name);
     101    dumpMaps(tmp->child);
    99102    tmp=tmp->next;
    100103  }
     
    105108 *
    106109 * @param m the map to dump
    107  * @param file_path the full path to the file name to store the map
    108  */
    109 void dumpMapsToFile(maps* m,char* file_path,int limit){
    110   FILE* file=fopen(file_path,"w+");
     110 * @param file the the file pointer to store the map
     111 */
     112void _dumpMapsToFile(maps* m,FILE* file,int limit){
    111113  maps* tmp=m;
    112114  int cnt=0;
    113115  while(tmp!=NULL){
    114116    fprintf(file,"[%s]\n",tmp->name);
    115     dumpMapToFile(tmp->content,file);
     117    if(tmp->child!=NULL){
     118      _dumpMapsToFile(tmp->child,file,limit);
     119    }else
     120      dumpMapToFile(tmp->content,file);
    116121    fflush(file);
    117122    tmp=tmp->next;
     
    121126  }
    122127  fflush(file);
     128}
     129
     130/**
     131 * Dump a maps to a file, see _dumpMapsToFile().
     132 *
     133 * @param m the map to dump
     134 * @param file_path the full path to the file name to store the map
     135 * @param limit the number limiting the maps to be dumped
     136 */
     137void dumpMapsToFile(maps* m,char* file_path,int limit){
     138  FILE* file=fopen(file_path,"w+");
     139  _dumpMapsToFile(m,file,limit);
     140  fflush(file);
    123141  fclose(file);
    124142}
     
    129147 * @param name the key to add to the map
    130148 * @param value the corresponding value to add to the map
    131  * @return the allocated map
     149 * @return a pointer to the allocated map
    132150 */
    133151map* createMap(const char* name,const char* value){
     
    136154  tmp->value=zStrdup(value);
    137155  tmp->next=NULL;
     156  return tmp;
     157}
     158
     159/**
     160 * Create a new maps with the given name
     161 *
     162 * @param name of the maps
     163 * @return the allocated map
     164 */
     165maps* createMaps(const char* name){
     166  maps* tmp = (maps *) malloc (MAPS_SIZE);
     167  tmp->name = zStrdup (name);
     168  tmp->content = NULL;
     169  tmp->child = NULL;
     170  tmp->next = NULL;
    138171  return tmp;
    139172}
     
    283316      freeMap(&_cursor->content);
    284317      free(_cursor->content);
     318    }
     319    if(_cursor->child!=NULL){
     320      freeMaps(&_cursor->child);
     321      free(_cursor->child);
    285322    }
    286323    if(_cursor->next!=NULL){
     
    362399    if(tmp->format!=NULL)
    363400      free(tmp->format);
     401    if(tmp->child!=NULL){
     402      freeElements(&tmp->child);
     403      free(tmp->child);
     404    }
    364405    freeIOType(&tmp->defaults);
    365406    if(tmp->defaults!=NULL)
     
    593634iotype* getIoTypeFromElement(elements* e,char *name, map* values){
    594635  elements* cursor=e;
    595   while(cursor!=NULL){
    596     if(strcasecmp(cursor->name,name)==0){
    597       if(contains(cursor->defaults->content,values)==true)
    598         return cursor->defaults;
    599       else{
    600         iotype* tmp=cursor->supported;
    601         while(tmp!=NULL){
    602           if(contains(tmp->content,values)==true)
    603             return tmp;     
    604           tmp=tmp->next;
     636  if(values!=NULL)
     637    while(cursor!=NULL){
     638      if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
     639        if(contains(cursor->defaults->content,values)==true)
     640          return cursor->defaults;
     641        else{
     642          iotype* tmp=cursor->supported;
     643          while(tmp!=NULL){
     644            if(contains(tmp->content,values)==true)
     645              return tmp;           
     646            tmp=tmp->next;
     647          }
    605648        }
    606649      }
    607     }
    608     cursor=cursor->next;
    609   }
     650      cursor=cursor->next;
     651    }
    610652  return NULL;
    611653}
     
    677719  maps* res=NULL;
    678720  if(_cursor!=NULL){
    679     res=(maps*)malloc(MAPS_SIZE);
    680     res->name=zStrdup(_cursor->name);
    681     res->content=NULL;
    682     res->next=NULL;
     721    res=createMaps(_cursor->name);
    683722    map* mc=_cursor->content;
    684723    if(mc!=NULL){
    685724      addMapToMap(&res->content,mc);
    686725      loadMapBinaries(&res->content,mc);
     726    }
     727    maps* mcs=_cursor->child;
     728    if(mcs!=NULL){
     729      res->child=dupMaps(&mcs);
    687730    }
    688731    res->next=dupMaps(&_cursor->next);
     
    709752        _cursor=_cursor->next;
    710753      maps* tmp1=getMaps(*mo,tmp->name);
    711       if(tmp1==NULL)
     754      if(tmp1==NULL){
    712755        _cursor->next=dupMaps(&tmp);
    713       else
     756        if(tmp->child!=NULL)
     757          _cursor->next->child=dupMaps(&tmp->child);
     758        else
     759          _cursor->next->child=NULL;
     760      }
     761      else{
    714762        addMapToMap(&tmp1->content,tmp->content);
     763        if(tmp->child!=NULL)
     764          tmp1->child=dupMaps(&tmp->child);
     765        else
     766          tmp1->child=NULL;
     767      }
    715768      _cursor=*mo;
    716769    }
     
    872925      _ztmpm->value=zStrdup(value);
    873926    }else{
    874       maps *tmp=(maps*)malloc(MAPS_SIZE);
    875       tmp->name=zStrdup(key);
     927      maps *tmp=createMaps(key);
    876928      tmp->content=createMap(subkey,value);
    877       tmp->next=NULL;
    878929      addMapsToMaps(&_tmpm,tmp);
    879930      freeMaps(&tmp);
     
    881932    }
    882933  }else{
    883     maps *tmp=(maps*)malloc(MAPS_SIZE);
    884     tmp->name=zStrdup(key);
     934    maps *tmp=createMaps(key);
    885935    tmp->content=createMap(subkey,value);
    886     tmp->next=NULL;
    887936    addMapsToMaps(&m,tmp);
    888937    freeMaps(&tmp);
    889938    free(tmp);
    890939  }
     940}
     941
     942/**
     943 * Create an empty elements
     944 *
     945 * @return a pointer to the allocated elements
     946 */
     947elements* createEmptyElements(){
     948  elements* res=(elements*)malloc(ELEMENTS_SIZE);
     949  res->name=NULL;
     950  res->content=NULL;
     951  res->metadata=NULL;
     952  res->format=NULL;
     953  res->defaults=NULL;
     954  res->supported=NULL;
     955  res->child=NULL;
     956  res->next=NULL;
     957  return res;
     958}
     959
     960/**
     961 * Create a named elements
     962 *
     963 * @param name the elements name
     964 * @return a pointer to the allocated elements
     965 */
     966elements* createElements(char* name){
     967  elements* res=(elements*)malloc(ELEMENTS_SIZE);
     968  res->name=zStrdup(name);
     969  res->content=NULL;
     970  res->metadata=NULL;
     971  res->format=NULL;
     972  res->defaults=NULL;
     973  res->supported=NULL;
     974  res->child=NULL;
     975  res->next=NULL;
     976  return res;
     977}
     978
     979/**
     980 * Set the name of an elements
     981 *
     982 * @param name the elements name
     983 * @return a pointer to the allocated elements
     984 */
     985void setElementsName(elements** elem,char* name){
     986  elements* res=*elem;
     987  res->name=zStrdup(name);
     988  res->content=NULL;
     989  res->metadata=NULL;
     990  res->format=NULL;
     991  res->defaults=NULL;
     992  res->supported=NULL;
     993  res->child=NULL;
     994  res->next=NULL;
    891995}
    892996
     
    9211025      ioc++;
    9221026    }
     1027    if(tmp->child!=NULL){
     1028      fprintf(stderr," > CHILD \n");
     1029      dumpElements(tmp->child);
     1030    }
    9231031    fprintf(stderr,"------------------\n");
    9241032    tmp=tmp->next;
     
    9311039 * @param e the elements to dump
    9321040 */
    933 void dumpElementsAsYAML(elements* e){
     1041void dumpElementsAsYAML(elements* e,int level){
    9341042  elements* tmp=e;
    9351043  int i;
    9361044  while(tmp!=NULL){
    937     for(i=0;i<2;i++)
     1045    for(i=0;i<2+(4*level);i++)
    9381046      fprintf(stderr," ");
    9391047    fprintf(stderr,"%s:\n",tmp->name);
    9401048    map* mcurs=tmp->content;
    9411049    while(mcurs!=NULL){
    942       for(i=0;i<4;i++)
     1050      for(i=0;i<4+(4*level);i++)
    9431051        fprintf(stderr," ");
    9441052      _dumpMap(mcurs);
     
    9471055    mcurs=tmp->metadata;
    9481056    if(mcurs!=NULL){
    949       for(i=0;i<4;i++)
     1057      for(i=0;i<4+(4*level);i++)
    9501058        fprintf(stderr," ");
    9511059      fprintf(stderr,"MetaData:\n");
    9521060      while(mcurs!=NULL){
    953         for(i=0;i<6;i++)
     1061        for(i=0;i<6+(4*level);i++)
    9541062          fprintf(stderr," ");
    9551063        _dumpMap(mcurs);
     
    9571065      }
    9581066    }
    959     for(i=0;i<4;i++)
     1067    for(i=0;i<4+(4*level);i++)
    9601068      fprintf(stderr," ");
    961     fprintf(stderr,"%s:\n",tmp->format);
     1069    if(tmp->format!=NULL)
     1070      fprintf(stderr,"%s:\n",tmp->format);
     1071    else{
     1072      fprintf(stderr,"Child:\n");
     1073      if(tmp->child!=NULL)
     1074        dumpElementsAsYAML(tmp->child,level+1);
     1075    }
    9621076    iotype* tmpio=tmp->defaults;
    9631077    int ioc=0;
    9641078    while(tmpio!=NULL){
    965       for(i=0;i<6;i++)
     1079      for(i=0;i<6+(4*level);i++)
    9661080        fprintf(stderr," ");
    9671081      fprintf(stderr,"default:\n");
    9681082      mcurs=tmpio->content;
    9691083      while(mcurs!=NULL){
    970         for(i=0;i<8;i++)
     1084        for(i=0;i<8+(4*level);i++)
    9711085          fprintf(stderr," ");
    9721086        if(strcasecmp(mcurs->name,"range")==0){
     
    9821096    ioc=0;
    9831097    while(tmpio!=NULL){
    984       for(i=0;i<6;i++)
     1098      for(i=0;i<6+(4*level);i++)
    9851099        fprintf(stderr," ");
    9861100      fprintf(stderr,"supported:\n");
    9871101      mcurs=tmpio->content;
    9881102      while(mcurs!=NULL){
    989         for(i=0;i<8;i++)
     1103        for(i=0;i<8+(4*level);i++)
    9901104          fprintf(stderr," ");
    9911105        if(strcasecmp(mcurs->name,"range")==0){
     
    10551169    else
    10561170      tmp->supported=NULL;
     1171    if(cursor->child!=NULL)
     1172      tmp->child=dupElements(cursor->child);
     1173    else
     1174      tmp->child=NULL;
    10571175    tmp->next=dupElements(cursor->next);
    10581176  }
     
    10751193  }
    10761194}
    1077  
     1195
     1196/**
     1197 * Set the name of a service
     1198 *
     1199 * @param name the service name
     1200 */
     1201void setServiceName(service** serv,char* name){
     1202  service* res=*serv;
     1203  res->name=zStrdup(name);
     1204  res->content=NULL;
     1205  res->metadata=NULL;
     1206  res->inputs=NULL;
     1207  res->outputs=NULL;
     1208}
     1209
    10781210/**
    10791211 * Dump a service on stderr
     
    11261258  if(s->inputs!=NULL){
    11271259    fprintf(stderr,"\ninputs:\n");
    1128     dumpElementsAsYAML(s->inputs);
     1260    dumpElementsAsYAML(s->inputs,0);
    11291261  }
    11301262  if(s->outputs!=NULL){
    11311263    fprintf(stderr,"\noutputs:\n");
    1132     dumpElementsAsYAML(s->outputs);
     1264    dumpElementsAsYAML(s->outputs,0);
    11331265  }
    11341266}
  • trunk/zoo-project/zoo-kernel/service.h

    r788 r790  
    154154 */
    155155//#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
    156 #define MAPS_SIZE sizeof(char*)+sizeof(map*)+sizeof(maps*)
     156#define MAPS_SIZE sizeof(char*)+sizeof(map*)+(2*sizeof(maps*))
    157157/**
    158158 * The memory size to create a service
     
    205205    char* name; //!< the maps name
    206206    struct map* content; //!< the content map
     207    struct maps* child; //!< the child maps
    207208    struct maps* next; //!< the pointer to the next maps if any or NULL
    208209  } maps;
     
    268269  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*,int);
    269270  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
     271  ZOO_DLL_EXPORT maps* createMaps(const char*);
    270272  ZOO_DLL_EXPORT int count(map*);
    271273  ZOO_DLL_EXPORT bool hasKey(map*,const char*);
     
    278280 
    279281
     282  ZOO_DLL_EXPORT elements* createEmptyElements();
     283  ZOO_DLL_EXPORT elements* createElements(char*);
     284  ZOO_DLL_EXPORT void setElementsName(elements**,char*);
    280285  ZOO_DLL_EXPORT bool hasElement(elements*,const char*);
    281286  ZOO_DLL_EXPORT elements* getElements(elements*,char*);
    282287  ZOO_DLL_EXPORT void freeIOType(iotype**);
    283288  ZOO_DLL_EXPORT void freeElements(elements**);
     289  ZOO_DLL_EXPORT void setServiceName(service**,char*);
    284290  ZOO_DLL_EXPORT void freeService(service**);
    285291  ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
     
    301307  ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*);
    302308  ZOO_DLL_EXPORT void dumpElements(elements*);
    303   ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*);
     309  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*,int);
    304310  ZOO_DLL_EXPORT elements* dupElements(elements*);
    305311  ZOO_DLL_EXPORT void addToElements(elements**,elements*);
  • trunk/zoo-project/zoo-kernel/service_conf.y

    r788 r790  
    3434static bool wait_mainmetadata=false;
    3535static bool wait_metadata=false;
     36static bool wait_nested=false;
    3637static bool wait_inputs=false;
    3738static bool wait_defaults=false;
     
    4748static int previous_data=0;
    4849static int current_data=0;
     50static int nested_level=0;
    4951// namespace
    5052using namespace std;
     
    145147  dumpMap(current_content);
    146148#endif
    147   if(my_service->content==NULL){
     149  if(my_service->content==NULL && current_content!=NULL){
    148150#ifdef DEBUG_SERVICE_CONF
    149151    fprintf(stderr,"NO CONTENT\n");
     
    156158    wait_maincontent=false;
    157159  }
     160  if(strncasecmp($2,"EndNested",9)==0){
     161#ifdef DEBUG_SERVICE_CONF
     162      fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__);
     163      fflush(stderr);
     164#endif
     165      nested_level-=1;
     166      if(nested_level==0){
     167        wait_nested=false;
     168      }
     169  }
     170
    158171  if(strncasecmp($2,"DataInputs",10)==0){
    159172    if(current_element==NULL){
     
    167180#endif
    168181      current_element=NULL;
    169       current_element=(elements*)malloc(ELEMENTS_SIZE);
    170       current_element->name=NULL;
    171       current_element->content=NULL;
    172       current_element->metadata=NULL;
    173       current_element->format=NULL;
    174       current_element->defaults=NULL;
    175       current_element->supported=NULL;
    176       current_element->child=NULL;
    177       current_element->next=NULL;
     182      current_element=createEmptyElements();
    178183    }
    179184    wait_inputs=true;
     
    217222        fflush(stderr);
    218223#endif
    219         current_element=(elements*)malloc(ELEMENTS_SIZE);
    220         current_element->name=NULL;
    221         current_element->content=NULL;
    222         current_element->metadata=NULL;
    223         current_element->format=NULL;
    224         current_element->defaults=NULL;
    225         current_element->supported=NULL;
    226         current_element->child=NULL;
    227         current_element->next=NULL;
     224        current_element=createEmptyElements();
    228225      }
    229226      wait_outputs=1;
     
    269266          current_element->defaults=NULL;
    270267          current_element->supported=NULL;
     268          current_element->child=NULL;
    271269          current_content=NULL;
    272270        }
     
    285283            }
    286284#ifdef DEBUG_SERVICE_CONF
    287   printf("* Identifiant : %s\n",$2);
    288   fflush(stdout);
     285  fprintf(stderr,"* Identifiant : %s\n",$2);
     286  fflush(stderr);
    289287#endif
    290288}
     
    340338     current_content=NULL;
    341339     current_element->supported=NULL;
     340     current_element->child=NULL;
    342341     current_element->next=NULL;
     342   }
     343   if(strncasecmp($2,"EndNested",9)==0){
     344     if(current_data==1){
     345       elements* cursor=my_service->inputs;
     346       while(cursor->next!=NULL)
     347         cursor=cursor->next;
     348       if(nested_level>1){
     349         for(int j=0;j<nested_level-1;j++){
     350           cursor=cursor->child;
     351           while(cursor->next!=NULL)
     352             cursor=cursor->next;
     353         }
     354       }
     355       if(cursor->child==NULL){
     356         cursor->child=dupElements(current_element);
     357       }else{
     358         addToElements(&cursor->child,current_element);
     359       }
     360     }else{
     361       if(current_element->name!=NULL){
     362         elements* cursor=my_service->outputs;
     363         while(cursor->next!=NULL)
     364           cursor=cursor->next;
     365         if(nested_level>1){
     366           for(int j=0;j<nested_level-1;j++){
     367             cursor=cursor->child;
     368             while(cursor->next!=NULL)
     369               cursor=cursor->next;
     370           }
     371         }
     372         if(cursor->child==NULL){
     373           cursor->child=dupElements(current_element);
     374         }else
     375           addToElements(&cursor->child,current_element);
     376       }
     377     }
     378     freeElements(&current_element);
     379     free(current_element);
     380     current_element=NULL;
     381     current_element=createEmptyElements();
     382     nested_level-=1;
     383     if(nested_level==0){
     384       wait_nested=false;       
     385     }
    343386   }
    344387 }
     
    395438        current_element->defaults=NULL;
    396439        current_element->supported=NULL;
     440        current_element->child=NULL;
    397441      }else{
    398442        if(wait_mainmetadata){
     
    428472    current_content=NULL;
    429473    current_element->supported=NULL;
     474    current_element->child=NULL;
    430475    current_element->next=NULL;
    431476  }
     
    443488      }else{
    444489        current_element->supported=NULL;
     490        current_element->child=NULL;
    445491        current_element->next=NULL;
    446492      }
     
    553599  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
    554600#endif
    555 //  if(data==-1){
    556 //    data=1;
    557601  if(::data==-1){ // knut: add namespace to avoid ambiguous symbol
    558602    ::data=1;   
    559603    if($1!=NULL){
    560604      char *cen=zStrdup($1);
    561       my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
    562605      cen[strlen(cen)-1]=0;
    563606      cen+=1;
    564       sprintf(my_service->name,"%s",cen);
     607      setServiceName(&my_service,cen);
    565608      cen-=1;
    566609      free(cen);
    567       my_service->content=NULL;
    568       my_service->metadata=NULL;
    569       my_service->inputs=NULL;
    570       my_service->outputs=NULL;
    571610    }
    572611  } else {
     
    579618        }
    580619        else{
    581           addToElements(&my_service->inputs,current_element);
     620          if(wait_nested){
     621            elements* cursor=my_service->inputs;
     622            while(cursor->next!=NULL)
     623              cursor=cursor->next;
     624            if(nested_level>1){
     625              for(int j=0;j<nested_level-1;j++){
     626                cursor=cursor->child;
     627                while(cursor->next!=NULL)
     628                  cursor=cursor->next;
     629              }
     630            }
     631            if(cursor->child==NULL){
     632              cursor->child=dupElements(current_element);
     633            }else{
     634              addToElements(&cursor->child,current_element);
     635            }
     636          }else
     637            addToElements(&my_service->inputs,current_element);
     638        }
     639        if(current_element->format==NULL){
     640          wait_nested=true;
     641          nested_level+=1;
     642          if(current_content!=NULL){
     643            elements* cursor=my_service->inputs;
     644            while(cursor->next!=NULL)
     645              cursor=cursor->next;
     646            if(nested_level>1){
     647              for(int j=0;j<nested_level-1;j++){
     648                cursor=cursor->child;
     649                while(cursor->next!=NULL)
     650                  cursor=cursor->next;
     651              }
     652            }
     653            addMapToMap(&cursor->content,current_content);
     654            freeMap(&current_content);
     655            free(current_content);
     656            current_content=NULL;
     657          }
    582658        }
    583659#ifdef DEBUG_SERVICE_CONF
     
    593669        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
    594670#endif
    595         current_element=(elements*)malloc(ELEMENTS_SIZE);
    596         current_element->name=NULL;
    597         current_element->content=NULL;
    598         current_element->metadata=NULL;
    599         current_element->format=NULL;
    600         current_element->defaults=NULL;
    601         current_element->supported=NULL;
    602         current_element->next=NULL;
     671        current_element=createEmptyElements();
    603672      }
    604673      if(current_element->name==NULL){
     
    613682        if($1!=NULL){
    614683          char *cen=zStrdup($1);
    615           current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
    616684          cen[strlen(cen)-1]=0;
    617685          cen+=1;
    618           sprintf(current_element->name,"%s",cen);
     686          setElementsName(&current_element,cen);
    619687          cen-=1;
    620688          free(cen);
     
    622690          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
    623691#endif
    624           current_element->content=NULL;
    625           current_element->metadata=NULL;
    626           current_element->format=NULL;
    627           current_element->defaults=NULL;
    628           current_element->supported=NULL;
    629           current_element->next=NULL;
    630692#ifdef DEBUG_SERVICE_CONF
    631693          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
     
    659721            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
    660722#endif
    661             current_element=(elements*)malloc(ELEMENTS_SIZE);
    662             current_element->name=NULL;
    663             current_element->content=NULL;
    664             current_element->metadata=NULL;
    665             current_element->format=NULL;
    666             current_element->defaults=NULL;
    667             current_element->supported=NULL;
    668             current_element->next=NULL;
     723            current_element=createEmptyElements();
    669724          }
    670725          if(current_element->name==NULL){
     
    675730            if($1!=NULL){
    676731              char *cen=zStrdup($1);
    677               current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
    678732              cen[strlen(cen)-1]=0;
    679733              cen+=1;
    680               sprintf(current_element->name,"%s",cen);
     734              setElementsName(&current_element,cen);
    681735              cen-=1;
    682736              free(cen);
    683               current_element->content=NULL;
    684               current_element->metadata=NULL;
    685               current_element->format=NULL;
    686               current_element->defaults=NULL;
    687               current_element->supported=NULL;
    688               current_element->next=NULL;
    689737            }
    690738          }
     
    696744            if(my_service->outputs==NULL)
    697745              my_service->outputs=dupElements(current_element);
    698             else
    699               addToElements(&my_service->outputs,current_element);
     746            else{
     747              if(wait_nested){
     748                elements* cursor=my_service->outputs;
     749                while(cursor->next!=NULL)
     750                  cursor=cursor->next;
     751                if(nested_level>1){
     752                  for(int j=0;j<nested_level-1;j++){
     753                    cursor=cursor->child;
     754                    while(cursor->next!=NULL)
     755                      cursor=cursor->next;
     756                  }
     757                }
     758                if(cursor->child==NULL){
     759                  cursor->child=dupElements(current_element);
     760                }else
     761                  addToElements(&cursor->child,current_element);
     762              }else
     763                addToElements(&my_service->outputs,current_element);
     764            }
     765            if(current_element->format==NULL){
     766              wait_nested=true;
     767              nested_level+=1;
     768              if(current_content!=NULL){
     769                elements* cursor=my_service->outputs;
     770                while(cursor->next!=NULL)
     771                  cursor=cursor->next;
     772                if(nested_level>1){
     773                  for(int j=0;j<nested_level-1;j++){
     774                    cursor=cursor->child;
     775                    while(cursor->next!=NULL)
     776                      cursor=cursor->next;
     777                  }
     778                }
     779                addMapToMap(&cursor->content,current_content);
     780                freeMap(&current_content);
     781                free(current_content);
     782                current_content=NULL;
     783              }
     784            }
     785
    700786#ifdef DEBUG_SERVICE_CONF
    701787            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
     
    705791            free(current_element);
    706792            current_element=NULL;
    707             current_element=(elements*)malloc(ELEMENTS_SIZE);
     793           
    708794            char *cen=zStrdup($1);
    709             current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
    710795            cen[strlen(cen)-1]=0;
    711796            cen+=1;
    712             sprintf(current_element->name,"%s",cen);
     797            current_element=createElements(cen);
    713798            cen-=1;
    714799            free(cen);
    715             current_element->content=NULL;
    716             current_element->metadata=NULL;
    717             current_element->format=NULL;
    718             current_element->defaults=NULL;
    719             current_element->supported=NULL;
    720             current_element->next=NULL;
    721800          }
    722801          else{
     
    727806            if($1!=NULL){
    728807              char *cen=zStrdup($1);
    729               current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
    730808              cen[strlen(cen)-1]=0;
    731809#ifdef DEBUG
     
    733811#endif
    734812              cen+=1;
    735               sprintf(current_element->name,"%s",cen);
     813              setElementsName(&current_element,cen);
    736814              cen-=1;
    737815              free(cen);
    738               current_element->content=NULL;
    739               current_element->metadata=NULL;
    740               current_element->format=NULL;
    741               current_element->defaults=NULL;
    742               current_element->supported=NULL;
    743               current_element->next=NULL;
    744816            }
    745817          }
     
    780852  }
    781853#ifdef DEBUG_SERVICE_CONF
    782   fprintf(stderr,"(STARTING)FREE current_element\n");
    783 #endif
     854  fprintf(stderr,"(STARTING)FREE current_element %s\n",file);
     855#endif
     856  fflush(stderr);
     857  fflush(stdout);
    784858  if(current_element!=NULL){
    785859    freeElements(&current_element);
     
    797871  wait_outputs=-1;
    798872  wait_data=false;
     873  wait_nested=false;
    799874//data=-1;
    800875  ::data=-1; // knut: add namespace to avoid ambiguous symbol
     
    831906      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
    832907#endif
    833       addToElements(&my_service->outputs,current_element);
     908      if(wait_nested){
     909        elements* cursor=my_service->outputs;
     910        while(cursor->next!=NULL)
     911          cursor=cursor->next;
     912        if(nested_level>1){
     913          for(int j=0;j<nested_level-1;j++){
     914            cursor=cursor->child;
     915            while(cursor->next!=NULL)
     916              cursor=cursor->next;
     917          }
     918        }
     919        if(cursor->child==NULL){
     920          cursor->child=dupElements(current_element);
     921        }else
     922          addToElements(&cursor->child,current_element);
     923      }else
     924        addToElements(&my_service->outputs,current_element);
    834925    }
    835926#ifdef DEBUG_SERVICE_CONF
  • trunk/zoo-project/zoo-kernel/service_internal_java.c

    r781 r790  
    251251      if (pValue != (jint)NULL){
    252252        res=pValue;
    253         m=mapsFromHashMap(env,arg1,scHashMapClass);
    254         *main_conf=m;
    255         outputs=mapsFromHashMap(env,arg3,scHashMapClass);
    256         *real_outputs=outputs;
    257 
     253        freeMaps(real_outputs);
     254        free(*real_outputs);
     255        freeMaps(main_conf);
     256        free(*main_conf);
     257        *main_conf=mapsFromHashMap(env,arg1,scHashMapClass);
     258        *real_outputs=mapsFromHashMap(env,arg3,scHashMapClass);
    258259#ifdef DEBUG
    259260        fprintf(stderr,"Result of call: %i\n", pValue);
     
    757758    jobject jk=(*env)->CallObjectMethod(env,tmp,getKey_mid);
    758759#endif
    759     maps* cmap=(maps*)malloc(sizeof(maps));
    760 #ifdef JAVA7
    761     cmap->name=(char*)(*env).GetStringUTFChars((jstring)jk, NULL);
    762 #else
    763     cmap->name=(*env)->GetStringUTFChars(env, jk, NULL);
    764 #endif
     760    maps* cmap=createMaps(
     761#ifdef JAVA7
     762      (char*)(*env).GetStringUTFChars((jstring)jk, NULL)
     763#else
     764      (*env)->GetStringUTFChars(env, jk, NULL)
     765#endif
     766                          );
    765767#ifdef DEBUG
    766768    fprintf(stderr," / %s \n",cmap->name);
    767769#endif
    768770    cmap->content=res;
    769     cmap->next=NULL;
    770771    if(final_res==NULL)
    771772      final_res=dupMaps(&cmap);
     
    780781  fprintf(stderr,"mapsFromHashMap end\n");
    781782#endif
    782 
    783783  return final_res;
    784784}
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r784 r790  
    425425  while(tmp!=NULL){
    426426    JSObject *pval=JSObject_FromMap(cx,tmp->content);
     427    if(tmp->child!=NULL){
     428      JSObject *pvalc=JSObject_FromMaps(cx,tmp->child);
     429      jsval pvaljc=OBJECT_TO_JSVAL(pvalc);
     430      JS_SetProperty(cx, pval, "child", &pvaljc);
     431    }
    427432    jsval pvalj=OBJECT_TO_JSVAL(pval);
    428433    JS_SetProperty(cx, res, tmp->name, &pvalj);
     
    548553       
    549554        tmp=JS_EncodeString(cx,jsmsg);
    550         tres=(maps*)malloc(MAPS_SIZE);
    551         tres->name=zStrdup(tmp);
    552         tres->content=NULL;
    553         tres->next=NULL;
     555        tres=createMaps(tmp);
    554556
    555557        jsval nvp=JSVAL_NULL;
     
    567569        }
    568570
     571        jsval nvp0=JSVAL_NULL;
     572        JSObject *nvp01=JSVAL_TO_OBJECT(JSVAL_NULL);
     573        if((JS_GetProperty(cx, nvp1, "child", &nvp0)==JS_FALSE)){
     574#ifdef JS_DEBUG
     575          fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,tmp);
     576#endif
     577        }
     578        JS_ValueToObject(cx,nvp0,&nvp01);
     579        jsval nvp01j=OBJECT_TO_JSVAL(nvp01);
     580        if(!JSVAL_IS_NULL(nvp01j)){
     581          tres->child=mapsFromJSObject(cx,nvp01j);
     582        }
     583
    569584        if(res==NULL)
    570585          res=dupMaps(&tres);
     
    574589        free(tres);
    575590        tres=NULL;
    576                
    577591      }
    578592      JS_DestroyIdArray(cx,idp);
     
    725739      fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,tmp,tmp1);
    726740#endif
    727       if(res!=NULL){
    728 #ifdef JS_DEBUG
    729         fprintf(stderr,"%s - %s\n",tmp,tmp1);
    730 #endif
    731         addToMap(res,tmp,tmp1);
    732       }
    733       else{
    734         res=createMap(tmp,tmp1);
    735         res->next=NULL;
     741      if(strcasecmp(tmp,"child")!=0){
     742        if(res!=NULL){
     743#ifdef JS_DEBUG
     744          fprintf(stderr,"%s - %s\n",tmp,tmp1);
     745#endif
     746          addToMap(res,tmp,tmp1);
     747        }
     748        else{
     749          res=createMap(tmp,tmp1);
     750          res->next=NULL;
     751        }
    736752      }
    737753      free(tmp);
  • trunk/zoo-project/zoo-kernel/service_internal_perl.c

    r348 r790  
    105105int hash_to_maps(HV * hh,maps** m){
    106106        hv_iterinit(hh);
    107         *m = (maps *)malloc(MAPS_SIZE);
    108107        maps * tmp = *m;
    109108        HE * he = hv_iternext(hh);
     
    111110        while (he != NULL) {
    112111                //fprintf(stderr,"key ===> %s \n",HeKEY(he));
    113                 tmp->name = HeKEY(he);
     112                tmp=createMaps(HeKEY(he));
    114113                hash_to_map((HV *) SvRV(HeVAL(he)),&mm);
    115114                tmp->content = mm;
     115                if(*m==NULL)
     116                  *m=tmp;
    116117                he = hv_iternext(hh);
    117118                if (he != NULL){
    118                         tmp->next = (maps *)malloc(MAPS_SIZE);
    119119                        tmp= tmp->next;
    120120                }
  • trunk/zoo-project/zoo-kernel/service_internal_php.c

    r784 r790  
    306306  while(tmp!=NULL){
    307307    map* sMap=getMapArray(tmp,"size",0);   
    308         if(strncmp(tmp->name,"value",5)==0 && sMap!=NULL && tmp->value != NULL){
     308    if(strncmp(tmp->name,"value",5)==0 && sMap!=NULL && tmp->value != NULL){
    309309      tres=add_assoc_stringl(mapArray,tmp->name,tmp->value,atoi(sMap->value),1);
    310         }
    311         else if (tmp->value != NULL) {
     310    }
     311    else if (tmp->value != NULL) {
    312312      tres=add_assoc_string(mapArray,tmp->name,tmp->value,1);
    313         }
     313    }
    314314    tmp=tmp->next;
    315315  }
     
    362362       * String Key / Associative
    363363       */
    364       cursor=(maps*)malloc(MAPS_SIZE);
    365       cursor->name=strdup(key);
    366     }
     364      cursor=createMaps(key);
    367365#ifdef DEBUG   
    368     fprintf(stderr,"key : %s\n",key);
     366      fprintf(stderr,"key : %s\n",key);
    369367#endif 
    370     HashTable* t=HASH_OF(*ppzval);
    371 #ifdef DEBUG
    372     fprintf(stderr,"key : %s\n",key);
    373 #endif
    374     cursor->content=php_map_from_HasTable(t);
    375     cursor->next=NULL;
    376     if(final_res==NULL)
    377       final_res=cursor;
    378     else{
    379       addMapsToMaps(&final_res,cursor);
     368      HashTable* t=HASH_OF(*ppzval);
     369#ifdef DEBUG
     370      fprintf(stderr,"key : %s\n",key);
     371#endif
     372      cursor->content=php_map_from_HasTable(t);
     373      cursor->next=NULL;
     374      if(final_res==NULL)
     375        final_res=dupMaps(&cursor);
     376      else{
     377        addMapsToMaps(&final_res,cursor);
     378      }
    380379      freeMaps(&cursor);
    381380      free(cursor);
  • trunk/zoo-project/zoo-kernel/service_internal_php7.c

    r789 r790  
    355355    HashTable* tab = HASH_OF(&copy);
    356356               
    357     maps* node = (maps*) malloc(MAPS_SIZE);
    358     node->name = strdup(ZSTR_VAL(key));                                 
     357    maps* node = createMaps(ZSTR_VAL(key));                                     
    359358    node->content = php_hashtable_to_map(tab);
    360     node->next = NULL;
    361359               
    362360    if(res == NULL) {
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r784 r790  
    356356      if(pbt!=NULL)
    357357        free(pbt);
    358       pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
    359       sprintf(pbt,_("%s\nUnable to run your python process properly. Please check the following messages : %s"),tpbt,PyString_AsString(trace));
     358      char* format=_("%s\nUnable to run your python process properly. Please check the following messages : %s");
     359      pbt=(char*)malloc((strlen(format)+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     360      sprintf(pbt,format,tpbt,PyString_AsString(trace));
    360361    }
    361362    else{
    362363      if(pbt!=NULL)
    363364        free(pbt);
    364       pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));     
    365       sprintf(pbt,_("%s \n Unable to run your python process properly. Unable to provide any further information."),tpbt);
     365      char* format=_("%s \n Unable to run your python process properly. Unable to provide any further information.");
     366      pbt=(char*)malloc((strlen(format)+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     367      sprintf(pbt,format,tpbt);
    366368    }
    367369    free(tpbt);
     
    390392  while(tmp!=NULL){
    391393    PyObject* value=(PyObject*)PyDict_FromMap(tmp->content);
     394    if(tmp->child!=NULL){
     395      PyObject* cname=PyString_FromString("child");
     396      PyObject* childs=(PyObject*)PyDict_FromMaps(tmp->child);
     397      if(PyDict_SetItem(value,cname,childs)<0){
     398        fprintf(stderr,"Unable to set map value ...");
     399        return NULL;
     400      }
     401      Py_DECREF(cname);
     402    }
    392403    PyObject* name=PyString_FromString(tmp->name);
    393404    if(PyDict_SetItem(res,name,value)<0){
     
    543554            PyString_AsString(key),PyString_AsString(value));
    544555#endif
    545     cursor=(maps*)malloc(MAPS_SIZE);
    546     cursor->name=zStrdup(PyString_AsString(key));
     556    cursor=createMaps(PyString_AsString(key));
    547557    cursor->content=mapFromPyDict((PyDictObject*)value);
     558    PyObject* cname=PyString_FromString("child");
     559    PyObject* childs=PyDict_GetItem((PyObject*)value,cname);
     560    if(childs!=NULL)
     561      cursor->child=mapsFromPyDict((PyDictObject*)childs);
     562    Py_DECREF(cname);
    548563#ifdef DEBUG
    549564    dumpMap(cursor->content);
     
    626641            PyString_AsString(key),PyString_AsString(value));
    627642#endif
    628    
    629     if(strncmp(PyString_AsString(key),"value",5)==0){
    630       char *buffer=NULL;
    631       Py_ssize_t size;
     643    if(strncmp(PyString_AsString(key),"child",5)!=0){
     644      if(strncmp(PyString_AsString(key),"value",5)==0){
     645        char *buffer=NULL;
     646        Py_ssize_t size;
    632647#if PY_MAJOR_VERSION >= 3
    633       if(PyBytes_Check(value)){
    634         size=PyBytes_Size(value);
    635         buffer=PyBytes_AsString(value);
    636       }
    637       else
    638         if(PyUnicode_Check(value) && PyUnicode_READY(value) == 0){
    639           buffer=PyUnicode_AsUTF8AndSize(value,&size);
     648        if(PyBytes_Check(value)){
     649          size=PyBytes_Size(value);
     650          buffer=PyBytes_AsString(value);
     651        }
     652        else
     653          if(PyUnicode_Check(value) && PyUnicode_READY(value) == 0){
     654            buffer=PyUnicode_AsUTF8AndSize(value,&size);
     655          }
     656          else{
     657#ifdef DEBUG
     658            fprintf(stderr,"Unsupported return value.");
     659#endif
     660            return NULL;
     661          }
     662#else
     663        PyString_AsStringAndSize(value,&buffer,&size);
     664#endif     
     665        res = addToMapWithSize(res,PyString_AsString(key),buffer,size);
     666      }else{
     667        char* lkey=PyString_AsString(key);
     668        char* lvalue=PyString_AsString(value);
     669        if(res!=NULL){
     670          if(PyString_Size(value)>0)
     671            addToMap(res,lkey,lvalue);
    640672        }
    641673        else{
    642 #ifdef DEBUG
    643           fprintf(stderr,"Unsupported return value.");
    644 #endif
    645           return NULL;
    646         }
    647 #else
    648       PyString_AsStringAndSize(value,&buffer,&size);
    649 #endif     
    650           res = addToMapWithSize(res,PyString_AsString(key),buffer,size);
    651     }else{
    652       char* lkey=PyString_AsString(key);
    653       char* lvalue=PyString_AsString(value);
    654       if(res!=NULL){
    655         if(PyString_Size(value)>0)
    656           addToMap(res,lkey,lvalue);
    657       }
    658       else{
    659         if(PyString_Size(value)>0)
    660           res=createMap(lkey,lvalue);
     674          if(PyString_Size(value)>0)
     675            res=createMap(lkey,lvalue);
     676        }
    661677      }
    662678    }
  • trunk/zoo-project/zoo-kernel/service_internal_ruby.c

    r631 r790  
    354354            StringValueCStr(key),StringValueCStr(value));
    355355#endif
    356     cursor=(maps*)malloc(MAPS_SIZE);
    357     cursor->name=StringValueCStr(key);
     356    cursor=createMaps(StringValueCStr(key));
    358357    cursor->content=mapFromRubyHash(value);
    359     cursor->next=NULL;
    360358    if(res==NULL)
    361359      res=dupMaps(&cursor);
    362360    else
    363361      addMapsToMaps(&res,cursor);
    364     freeMap(&cursor->content);
    365     free(cursor->content);
     362    freeMaps(&cursor);
    366363    free(cursor);
    367364  }
  • trunk/zoo-project/zoo-kernel/service_internal_saga.c

    r760 r790  
    690690    tmpName[strlen(fext)+(strlen(gfile->value)+strlen(tmpSubName)-4)]=0;
    691691
    692     maps* louts=(maps*)malloc(MAPS_SIZE);
    693     louts->name=zStrdup(tinOut[i]);
     692    maps* louts=createMaps(tinOut[i]);
    694693    louts->content=createMap("mimeType","UNKOWN");
    695     louts->next=NULL;
    696694   
    697695    addToMap(arg,tinOut[i],tmpName);
     
    741739    addToMap(arg,"GRIDS","");
    742740
    743     maps* louts=(maps*)malloc(MAPS_SIZE);
    744     louts->name=zStrdup("GRIDS");
     741    maps* louts=createMaps("GRIDS");
    745742    louts->content=createMap("mimeType","UNKOWN");
    746     louts->next=NULL;
    747743
    748744    sagaExecuteCmd(conf,"io_gdal","0",arg,&louts);
     
    786782      addToMap(arg,"FILES",v->value);
    787783
    788     maps* louts=(maps*)malloc(MAPS_SIZE);
    789     louts->name=zStrdup("SHAPES");
     784    maps* louts=createMaps("SHAPES");
    790785    louts->content=createMap("mimeType","UNKOWN");
    791     louts->next=NULL;
    792786
    793787    sagaExecuteCmd(conf,"io_gdal","3",arg,&louts);
     
    832826    if(v!=NULL)
    833827      addToMap(arg,"SHAPES",v->value);
    834     maps* louts=(maps*)malloc(MAPS_SIZE);
    835     louts->name=zStrdup("TIN");
     828    maps* louts=createMaps("TIN");
    836829    louts->content=createMap("mimeType","UNKOWN");
    837     louts->next=NULL;
    838830    sagaExecuteCmd(conf,"tin_tools","2",arg,&louts);
    839831    map* tmp=getMapFromMaps(louts,"TIN","generated_file");
     
    887879
    888880    // Create the output maps
    889     maps* louts=(maps*)malloc(MAPS_SIZE);
    890     louts->name=zStrdup("TABLE");
     881    maps* louts=createMaps("TABLE");
    891882    louts->content=createMap("mimeType","UNKOWN");
    892     louts->next=NULL;
    893883
    894884    // Execute the saga command
     
    940930
    941931    // Create the output maps
    942     maps* louts=(maps*)malloc(MAPS_SIZE);
    943     louts->name=zStrdup("POINTS");
     932    maps* louts=createMaps("POINTS");
    944933    louts->content=createMap("mimeType","UNKOWN");
    945     louts->next=NULL;
    946934
    947935    // Execute the saga command
  • trunk/zoo-project/zoo-kernel/service_yaml.c

    r781 r790  
    8484  yaml_parser_set_input_file(&parser, fh);
    8585  /* BEGIN new code */
     86  int nleveld=-1;
    8687  int level=0;
    8788  int plevel=level;
     89  int nlevel=0;
     90  int pnlevel=0;
    8891  int ilevel=-1;
    8992  int blevel=-1;
    9093  int ttype=0;
     94  int outputs=-1;
     95  int noutputs=-1;
    9196  int wait_metadata=-1;
    9297  char *cur_key;
     
    145150      blevel++;
    146151      break;
    147     case YAML_SCALAR_TOKEN: 
     152    case YAML_SCALAR_TOKEN:
     153      if((blevel-1)/2<nlevel){
     154        pnlevel=nlevel;
     155        nlevel=(blevel-1)/2;
     156        nleveld=1;
     157      }else
     158        nleveld=-1;
    148159      if(ttype==0){
    149160        cur_key=zStrdup((char *)token.data.scalar.value);
     
    180191        current_content=NULL;
    181192        wait_metadata=1;
     193      }
     194      if(strcasecmp((char *)token.data.scalar.value,"Child")==0){
     195        elements* cursor=my_service->inputs;
     196        if(outputs==1)
     197          cursor=my_service->outputs;
     198        for(int i=0;(blevel/2)>1 && i<(blevel/2)-1 && cursor!=NULL;i++){
     199          while(cursor->next!=NULL)
     200            cursor=cursor->next;
     201          if(cursor->child!=NULL){
     202            cursor=cursor->child;
     203          }
     204        }
     205        if(current_content!=NULL){
     206          addMapToMap(&current_element->content,current_content);
     207          freeMap(&current_content);
     208          free(current_content);
     209          current_content=NULL;
     210        }
     211        if(current_element!=NULL){
     212          if(blevel/2>1 && cursor!=NULL){
     213            if(cursor->child==NULL)
     214              cursor->child=dupElements(current_element);
     215            else
     216              addToElements(&cursor->child,current_element);
     217          }
     218          else{
     219            if(outputs<0)
     220              if(my_service->inputs==NULL)
     221                my_service->inputs=dupElements(current_element);
     222              else
     223                addToElements(&my_service->inputs,current_element);
     224            else
     225              if(my_service->inputs==NULL)
     226                my_service->outputs=dupElements(current_element);
     227              else
     228                addToElements(&my_service->outputs,current_element);
     229          }
     230          freeElements(&current_element);
     231          free(current_element);
     232          current_element=NULL;
     233        }
     234        nlevel+=1;
    182235      }
    183236      if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"inputs")==0 && blevel==0){
     
    200253      }
    201254      if(ttype==0 && strcasecmp((char *)token.data.scalar.value,"outputs")==0 && blevel==1){
     255        outputs=1;
    202256        level++;
    203257#ifdef DEBUG_YAML
     
    303357      }
    304358
     359      if(strcasecmp(token.data.scalar.value,"default")!=0 && strcasecmp(token.data.scalar.value,"supported")!=0 && level==1 && (blevel-1)%2==0 && blevel!=1 && (blevel-1)/2==nlevel){
     360        if(current_element==NULL)
     361          current_element=createElements((char *)token.data.scalar.value);
     362        else{
     363          if(current_content!=NULL){
     364            if(current_element->defaults==NULL){
     365              current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
     366              current_element->defaults->content=NULL;
     367              current_element->defaults->next=NULL;
     368              addMapToMap(&current_element->defaults->content,current_content);
     369            }else{
     370              if(current_element->supported==NULL){
     371                current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
     372                current_element->supported->content=NULL;
     373                current_element->supported->next=NULL;
     374                addMapToMap(&current_element->supported->content,current_content);
     375              }else
     376                addMapToIoType(&current_element->supported,current_content);
     377            }
     378            freeMap(&current_content);
     379            free(current_content);
     380            current_content=NULL;
     381          }
     382         
     383          elements* cursor=my_service->inputs;
     384          if(outputs==1)
     385            cursor=my_service->outputs;
     386          int llevel=((blevel-1)/2);
     387          if(nleveld>0)
     388            llevel=((blevel-1)/2)+1;
     389          for(int i=0;llevel>1 && i<llevel-1 && cursor!=NULL;i++){
     390            while(cursor->next!=NULL)
     391              cursor=cursor->next;
     392            if(cursor->child!=NULL){
     393              cursor=cursor->child;
     394            }
     395          }
     396          if(llevel>1)
     397            if(cursor->child==NULL)
     398              cursor->child=dupElements(current_element);
     399            else
     400              addToElements(&cursor->child,current_element);
     401          else
     402            if(cursor==NULL)
     403              cursor=dupElements(current_element);
     404            else
     405              addToElements(&cursor,current_element);
     406          freeElements(&current_element);
     407          free(current_element);
     408          current_element=NULL;
     409          current_element=createElements((char *)token.data.scalar.value);
     410        }
     411      }
    305412      if(blevel==1 && level==1){
    306413        if(current_element!=NULL && current_content!=NULL){
     
    319426              addMapToIoType(&current_element->supported,current_content);
    320427          }
    321         }
    322         if(current_element!=NULL){
    323           if(my_service->inputs==NULL)
    324             my_service->inputs=dupElements(current_element);
    325           else
    326             addToElements(&my_service->inputs,current_element);
    327           freeElements(&current_element);
    328           free(current_element);
    329         }
     428          freeMap(&current_content);
     429          free(current_content);
     430          current_content=NULL;
     431        }
     432        if(nleveld<0){
     433          if(current_element!=NULL){
     434            if(outputs<0)
     435              if(my_service->inputs==NULL)
     436                my_service->inputs=dupElements(current_element);
     437              else
     438                addToElements(&my_service->inputs,current_element);
     439            else
     440              if(my_service->outputs==NULL)
     441                my_service->outputs=dupElements(current_element);
     442              else
     443                addToElements(&my_service->outputs,current_element);
     444            freeElements(&current_element);
     445            free(current_element);
     446          }
     447        }
     448        else{
     449          if(current_element!=NULL){
     450            elements* cursor=my_service->inputs;
     451            if(outputs==1)
     452              cursor=my_service->outputs;
     453            while(cursor->next!=NULL)
     454              cursor=cursor->next;
     455            for(int i=0;pnlevel>1 && i<pnlevel-1 && cursor!=NULL;i++){
     456              while(cursor->next!=NULL)
     457                cursor=cursor->next;
     458              if(cursor->child!=NULL){
     459                cursor=cursor->child;
     460              }
     461            }
     462            if(cursor->child==NULL)
     463              cursor->child=dupElements(current_element);
     464            else
     465              addToElements(&cursor->child,current_element);
     466            freeElements(&current_element);
     467            free(current_element);
     468          }
     469        }   
    330470        plevel=level;
    331         current_element=(elements*)malloc(ELEMENTS_SIZE);
    332         current_element->name=zStrdup((char *)token.data.scalar.value);
    333         current_element->content=NULL;
    334         current_element->metadata=NULL;
    335         current_element->format=NULL;
    336         current_element->defaults=NULL;
    337         current_element->supported=NULL;
    338         current_element->next=NULL;
    339        
     471        current_element=createElements((char *)token.data.scalar.value);       
    340472      }
    341473      if(blevel==1 && level==2){
     
    355487              addMapToIoType(&current_element->supported,current_content);
    356488          }
     489          freeMaps(&current_content);
     490          free(current_content);
     491          current_content=NULL;
    357492        }
    358493        if(current_element!=NULL){
     
    372507        }
    373508        plevel=level;
    374         current_element=(elements*)malloc(ELEMENTS_SIZE);
    375         current_element->name=zStrdup((char *)token.data.scalar.value);
    376         current_element->content=NULL;
    377         current_element->metadata=NULL;
    378         current_element->format=NULL;
    379         current_element->defaults=NULL;
    380         current_element->supported=NULL;
    381         current_element->next=NULL;
     509        current_element=createElements((char *)token.data.scalar.value);       
    382510       
    383511      }
     512
     513      if(noutputs>0)
     514        outputs=1;
     515      if(strcasecmp((char *)token.data.scalar.value,"outputs")==0 && ttype==0 && blevel==0){
     516        noutputs=1;
     517      }
     518     
    384519
    385520
     
    433568    current_content=NULL;
    434569  }
     570
    435571  if(current_element!=NULL){
    436     if(my_service->outputs==NULL)
    437       my_service->outputs=dupElements(current_element);
    438     else
    439       addToElements(&my_service->outputs,current_element);
     572    if(nlevel>0){
     573      elements* cursor=my_service->inputs;
     574      if(outputs==1)
     575        cursor=my_service->outputs;
     576      for(int i=0;nlevel>1 && i<nlevel-1 && cursor!=NULL;i++){
     577        while(cursor->next!=NULL)
     578          cursor=cursor->next;
     579        if(cursor->child!=NULL){
     580          cursor=cursor->child;
     581        }
     582      }
     583      if(cursor->child==NULL)
     584        cursor->child=dupElements(current_element);
     585      else
     586        addToElements(&cursor->child,current_element);
     587    }else{
     588      if(my_service->outputs==NULL)
     589        my_service->outputs=dupElements(current_element);
     590      else
     591        addToElements(&my_service->outputs,current_element);
     592    }
    440593    freeElements(&current_element);
    441594    free(current_element);
  • trunk/zoo-project/zoo-kernel/zoo_loader.c

    r745 r790  
    9595     strncasecmp(cgiRequestMethod,"post",4)==0){
    9696    if(cgiContentLength==0){
     97
    9798       char *buffer=new char[2];
    9899       char *res=NULL;
     
    387388      token=strtok_r(NULL,"&",&saveptr);
    388389    }
    389    
    390390  }
    391391
     
    393393    map* tmp=getMap(tmpMap,"dataInputs");
    394394    if(tmp!=NULL){
    395       addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11);
     395      if(strcasestr(strQuery,"dataInputs=")!=NULL)
     396        addToMap(tmpMap,"dataInputs",strcasestr(strQuery,"dataInputs=")+11);
     397      else
     398        addToMap(tmpMap,"dataInputs","None");
    396399    }
    397400  }
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r789 r790  
    770770
    771771  map *tmpReq = getMap (request_inputs, "xrequest");
    772  
     772
    773773  if(r_inputs2 != NULL && tmpReq != NULL) {
    774774    const char key[] = "rfile=";
     
    922922  if (m == NULL)
    923923    {
    924       return errorException (m, _("Unable to allocate memory"),
     924      return errorException (NULL, _("Unable to allocate memory"),
    925925                             "InternalError", NULL);
    926926    }
     927  m->child=NULL;
    927928  char ntmp[1024];
    928929#ifndef ETC_DIR
     
    15371538                                                           NULL);
    15381539                                  }
    1539 #ifdef DEBUG
    1540                                 printf
    1541                                   ("#################\n(%s) %s\n#################\n",
     1540#ifdef DEBUG_SERVICE_CONF
     1541                                fprintf
     1542                                  (stderr,"#################\n(%s) %s\n#################\n",
    15421543                                   r_inputs->value, buff1);
    15431544#endif
     
    17031704  map *postRequest = NULL;
    17041705  postRequest = getMap (request_inputs, "xrequest");
    1705 
     1706 
    17061707  if(vid==1 && postRequest==NULL){
    17071708    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request"); 
     
    18171818  maps *tmpmaps = request_input_real_format;
    18181819
    1819 
    18201820  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){
    18211821    freeMaps (&m);
     
    18281828    return 0;
    18291829  }
    1830 
    18311830
    18321831  // Define each env variable in runing environment
     
    19891988   *
    19901989   */
    1991   maps *_tmpMaps = (maps *) malloc (MAPS_SIZE);
    1992   _tmpMaps->name = zStrdup ("lenv");
     1990  maps *_tmpMaps = createMaps("lenv");
    19931991  char tmpBuff[100];
    19941992  struct ztimeval tp;
     
    19981996    sprintf (tmpBuff, "%i", (cpid + (int) time (NULL)));
    19991997  _tmpMaps->content = createMap ("osid", tmpBuff);
    2000   _tmpMaps->next = NULL;
    20011998  sprintf (tmpBuff, "%i", cpid);
    20021999  addToMap (_tmpMaps->content, "sid", tmpBuff);
     
    20812078          free (tcook);
    20822079          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
     2080          tmpSess->child=NULL;
    20832081          struct stat file_status;
    20842082          int istat = stat (session_file_path, &file_status);
     
    21062104    *environ;
    21072105#endif
    2108   _tmpMaps = (maps *) malloc (MAPS_SIZE);
    2109   _tmpMaps->name = zStrdup ("renv");
    2110   _tmpMaps->content = NULL;
    2111   _tmpMaps->next = NULL;
     2106  _tmpMaps = createMaps("renv");
    21122107  for (; s; ei++) {
    21132108    char* tmpName=zStrdup(s);
     
    22292224                     strlen (usid->value) + 7) * sizeof (char));                   
    22302225          sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
    2231           bmap = (maps *) malloc (MAPS_SIZE);
    2232           bmap->name=zStrdup("status");
     2226          bmap = createMaps("status");
    22332227          bmap->content=createMap("usid",usid->value);
    2234           bmap->next=NULL;
    22352228          addToMap(bmap->content,"sid",tmpm->value);
    22362229          addIntToMap(bmap->content,"pid",getpid());
  • trunk/zoo-project/zoo-services/gdal/grid/service.c

    r348 r790  
    10681068        Usage();
    10691069        GDALDestroyDriverManager();
     1070#ifndef ZOO_SERVICE
    10701071        exit( 2 );
     1072#else
     1073        fprintf(stderr,"pszSource %s\n",pszSource);
     1074        fprintf(stderr,"pszDest %s\n",pszDest);
     1075        return SERVICE_FAILED;
     1076#endif
    10711077    }
    10721078
  • trunk/zoo-project/zoo-services/hello-js/cgi-env/hello.js

    r423 r790  
    2929}
    3030
     31function hellojs2(conf,inputs,outputs){
     32    outputs["result"]["value"]="Hello "+inputs["S"]["child"]["nom"]["value"]+" "+inputs["S"]["child"]["prenom"]["value"]+" from the JS World !";
     33    outputs["result1"]["child"]["tata"]["value"]="a"
     34    //SERVICE_SUCEEDED
     35    return {"result": 3,"outputs":outputs};
     36}
     37
    3138function hellojs1(conf,inputs,outputs){
    3239        outputs["result"]["value"]="Hello "+inputs["S"]["value"]+" from the JS World !";
  • trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c

    r766 r790  
    591591/* -------------------------------------------------------------------- */
    592592#if GDAL_VERSION_MAJOR >= 2
    593       GDALDataset *poDS;
     593      GDALDataset *poDS
     594        = (GDALDataset*) GDALOpenEx( pszDataSource,
     595                                     GDAL_OF_READONLY | GDAL_OF_VECTOR,
     596                                     NULL, NULL, NULL );
    594597      GDALDataset *poODS;
    595598      GDALDriverManager* poR=GetGDALDriverManager();
    596599      GDALDriver          *poDriver = NULL;
    597600#else
    598       OGRDataSource* poDS;
     601      OGRDataSource* poDS
     602        = OGRSFDriverRegistrar::Open( pszDataSource, FALSE );
    599603      OGRDataSource *poODS;
    600604      OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     
    737741        if( poODS == NULL )
    738742        {
     743          poODS =
     744#if GDAL_VERSION_MAJOR >= 2
     745            (GDALDataset*) GDALOpenEx( pszDestDataSource,
     746                                       GDAL_OF_UPDATE | GDAL_OF_VECTOR,
     747                                       NULL, NULL, NULL )
     748#else
     749            OGRSFDriverRegistrar::Open( pszDestDataSource, TRUE )
     750#endif
     751            ;
     752          if( poODS == NULL )
     753            {
     754              fprintf( stderr, "FAILURE:\n"
     755                       "Unable to open existing output datasource `%s'.\n",
     756                       pszDestDataSource );
     757#ifdef ZOO_SERVICE
     758              char tmp[1024];
     759              sprintf(tmp,"Unable to open existing output datasource `%s'.",pszDestDataSource);
     760              setMapInMaps(conf,"lenv","message",tmp);
     761              return SERVICE_FAILED;
     762#else
     763              exit( 1 );
     764#endif
     765
    739766            fprintf( stderr,  "%s driver failed to create %s\n",
    740767                    pszFormat, pszDestDataSource );
    741 #ifdef ZOO_SERVICE
    742             char tmp[1024];
    743             sprintf(tmp,"%s driver failed to create %s",pszFormat, pszDestDataSource);
    744             setMapInMaps(conf,"lenv","message",tmp);
    745             return SERVICE_FAILED;
    746 #else
    747             exit( 1 );
    748 #endif
     768            }
    749769        }
    750770    }
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