source: trunk/zoo-project/zoo-kernel/service_conf.y @ 788

Last change on this file since 788 was 788, checked in by knut, 7 years ago

Implemented support for PHP 7: The Zend API for PHP 7/PHPNG is substantially different from older versions. Therefore, an alternative implementation of zoo_php_support is provided in the new source file service_internal_php7.c. Presently the Zoo kernel can be built with support for either PHP 7 or older versions, see the makefiles (for Windows) nmake.opt and makefile.vc. Other makefiles have not been updated.

Fixed problem with ambiguous symbol in service_conf.y. Fixed problem with conversion of line endings yielding extra bytes in _getStatusFile on Windows platforms. Removed call to free() stack memory in zoo_service_loader.c. Fixed issue with size of structs in service.h.

File size: 24.3 KB
RevLine 
[607]1/*
[1]2 * Author : Gérald FENOY
3 *
[621]4 * Copyright (c) 209-2015 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
[1]23 */
[607]24%{
[1]25
26#include <string>
27#include <stdio.h>
28#include <ctype.h>
29#include <service.h>
30
31static int tmp_count=1;
32static int defaultsc=0;
33static bool wait_maincontent=true;
34static bool wait_mainmetadata=false;
35static bool wait_metadata=false;
36static bool wait_inputs=false;
37static bool wait_defaults=false;
38static bool wait_supporteds=false;
[618]39static bool wait_outputs=false;
[1]40static bool wait_data=false;
41static service* my_service=NULL;
42static map* current_content=NULL;
43static elements* current_element=NULL;
44static char* curr_key;
45static int debug=0;
46static int data=-1;
47static int previous_data=0;
48static int current_data=0;
49// namespace
50using namespace std;
51
52// srerror
[114]53void srerror(const char *s);
[1]54
55// usage ()
56void usage(void) ;
57
58// srdebug
59extern int srdebug;
60
61extern char srtext[];
62
63// srlineno
64extern int srlineno;
65
66// srin
67extern FILE* srin;
68
69// srlex
70extern int srlex(void);
[9]71extern int srlex_destroy(void);
[1]72
73%}
74
75
76
77%union
78{char * s;char* chaine;char* key;char* val;}
79
80// jetons //
81%token <s> ID
82%token <s> CHAINE
[607]83
[1]84%token INFCAR SUPCAR
[607]85
[1]86/* / = a1  texte "texte" */
87%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID
88%type <chaine> PAIR
89%type <chaine> EPAIR
90%type <chaine> SPAIR
[607]91
[1]92/* <!-- xxx -> <? xxx yyy ?> */
93%token PI PIERROR /** COMMENT **/
[607]94
[1]95/* <!-- xxx -> <? xxx yyy ?> */
96%token ERREURGENERALE CDATA WHITESPACE NEWLINE
97%type <s> STag
98%type <s> ETag
99%type <s> ANID
100
[607]101// % start
102
[1]103%%
[607]104// document
[1]105// regle 1
106// on est a la racine du fichier xml
107document
108 : miscetoile element miscetoile {}
109 | contentetoile processid contentetoile document {}
110 ;
111
112miscetoile
[781]113 : miscetoile PIERROR {  srerror("processing instruction beginning with <?xml ?> impossible\n");}
[1]114 | miscetoile PI {}
115 | {}
116 ;
117// element
118// regle 39
119// OUVRANTE CONTENU FERMANTE obligatoirement
120// ou neutre
121// on ne peut pas avoir Epsilon
122// un fichier xml ne peut pas etre vide ou seulement avec un prolog
123element
124 : STag contentetoile ETag     
125{
126}
[20]127
[1]128// pour neutre
129// on a rien a faire, meme pas renvoyer l identificateur de balise
130// vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
131 | EmptyElemTag          {}
132 ;
[20]133
[1]134// STag
135// regle 40
136// BALISE OUVRANTE
137// on est obligé de faire appel a infcar et supcar
138// pour acceder aux start conditions DANSBALISE et INITIAL
139STag
140: INFCAR ID Attributeetoile SUPCAR
141{
[379]142#ifdef DEBUG_SERVICE_CONF
[621]143  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
[379]144  fflush(stderr);
[607]145  dumpMap(current_content);
[379]146#endif
[1]147  if(my_service->content==NULL){
148#ifdef DEBUG_SERVICE_CONF
149    fprintf(stderr,"NO CONTENT\n");
150#endif
[9]151    addMapToMap(&my_service->content,current_content);
152    freeMap(&current_content);
153    free(current_content);
[1]154    current_content=NULL;
155    my_service->metadata=NULL;
156    wait_maincontent=false;
157  }
[9]158  if(strncasecmp($2,"DataInputs",10)==0){
[1]159    if(current_element==NULL){
160#ifdef DEBUG_SERVICE_CONF
[104]161      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
[1]162#endif
163      freeElements(&current_element);
164      free(current_element);
165#ifdef DEBUG_SERVICE_CONF
[104]166      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
[1]167#endif
168      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;
[640]176      current_element->child=NULL;
[1]177      current_element->next=NULL;
178    }
179    wait_inputs=true;
180    current_data=1;
181    previous_data=1;
182  }
183  else
[9]184    if(strncasecmp($2,"DataOutputs",11)==0){
[1]185      if(wait_inputs==true){
186#ifdef DEBUG_SERVICE_CONF
[104]187        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
[9]188        fprintf(stderr,"CURRENT_ELEMENT\n");
189        dumpElements(current_element);
190        fprintf(stderr,"SERVICE INPUTS\n");
191        dumpElements(my_service->inputs);
192        dumpService(my_service);
[65]193#endif 
[469]194        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
[1]195          my_service->inputs=dupElements(current_element);
[9]196          my_service->inputs->next=NULL;
[469]197          freeElements(&current_element);
[9]198        }
[57]199        else if(current_element!=NULL && current_element->name!=NULL){
[9]200          addToElements(&my_service->inputs,current_element);
[469]201          freeElements(&current_element);
[57]202        }
[1]203#ifdef DEBUG_SERVICE_CONF
[9]204        fprintf(stderr,"CURRENT_ELEMENT\n");
[1]205        dumpElements(current_element);
[9]206        fprintf(stderr,"SERVICE INPUTS\n");
[1]207        dumpElements(my_service->inputs);
208        fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
209#endif
210        free(current_element);
211        current_element=NULL;
212        wait_inputs=false;
213      }
214      if(current_element==NULL){
215#ifdef DEBUG_SERVICE_CONF
[104]216        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
[379]217        fflush(stderr);
[1]218#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;
[640]226        current_element->child=NULL;
[1]227        current_element->next=NULL;
228      }
[607]229      wait_outputs=1;
[1]230      current_data=2;
[65]231      previous_data=2;
[1]232    }
233    else
[9]234      if(strncasecmp($2,"MetaData",8)==0){
[73]235        previous_data=current_data;
[1]236        current_data=3;
237        if(current_element!=NULL){
238#ifdef DEBUG_SERVICE_CONF
239          fprintf(stderr,"add current_content to current_element->content\n");
[104]240          fprintf(stderr,"LINE %d",__LINE__);
[1]241#endif
242          addMapToMap(&current_element->content,current_content);
243          freeMap(&current_content);
244          free(current_content);
[104]245          if(previous_data==1 || previous_data==2)
246            wait_metadata=true;
247          else
248            wait_mainmetadata=true;
[1]249        }
250        else{
[104]251          if(previous_data==1 || previous_data==2)
252            wait_metadata=true;
253          else
254            wait_mainmetadata=true;
[1]255        }
256        current_content=NULL;
257      }
258      else
[9]259        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
[76]260           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
261           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
[1]262          current_data=4;
[621]263          addMapToMap(&current_element->content,current_content);
264          freeMap(&current_content);
265          free(current_content);
266          current_element->next=NULL;
267          if($2!=NULL)
268            current_element->format=zStrdup($2);
269          current_element->defaults=NULL;
270          current_element->supported=NULL;
[1]271          current_content=NULL;
272        }
273        else
[9]274          if(strncasecmp($2,"Default",7)==0){
[1]275            wait_defaults=true;
276            current_data=5;
277          }
278          else
[9]279            if(strncasecmp($2,"Supported",9)==0){
[1]280              wait_supporteds=true;
281              if(wait_defaults==true){
282                defaultsc++;
283              }
284              current_data=5;
285            }
286#ifdef DEBUG_SERVICE_CONF
287  printf("* Identifiant : %s\n",$2);
[379]288  fflush(stdout);
[1]289#endif
290}
291 ;
[20]292
[1]293// Attributeetoile
294// regle 41
295// une liste qui peut etre vide d'attributs
296// utiliser la récursivité a gauche
297Attributeetoile
[621]298: Attributeetoile attribute  {}
[1]299 |                                {/* Epsilon */}
300 ;
[20]301
[1]302// attribute
303// regle 41
304// un attribut est compose d'un identifiant
305// d'un "="
306// et d'une définition de chaine de caractere
307// ( "xxx" ou 'xxx' )
308attribute
309 : ID Eq ATTVALUE               
310{
311#ifdef DEBUG_SERVICE_CONF
312  printf ("attribute : %s\n",$1) ;
313#endif
314}
315 ;
[20]316
[1]317// EmptyElemTag
318// regle 44
319// ICI ON DEFINIT NEUTRE
320// on ne renvoie pas de char*
321// parce qu'il n'y a pas de comparaisons a faire
322// avec un identifiant d'une balise jumelle
323EmptyElemTag
[226]324 : INFCAR ID Attributeetoile SLASH SUPCAR       {
[379]325#ifdef DEBUG_SERVICE_CONF
326  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
327#endif
[226]328   if(strncasecmp($2,"Default",7)==0){
329     wait_defaults=false;
330     current_data=previous_data;
331     if(current_element->defaults==NULL){
332       current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
333       current_element->defaults->content=NULL;
334     }
335     addMapToMap(&current_element->defaults->content,current_content);
336     freeMap(&current_content);
337     free(current_content);
338     current_element->defaults->next=NULL;
339     wait_defaults=false;
340     current_content=NULL;
341     current_element->supported=NULL;
342     current_element->next=NULL;
343   }
344 }
[1]345 ;
[20]346
[1]347// ETag
348// BALISE FERMANTE
349// les separateurs après ID sont filtrés
350ETag
351 : INFCAR SLASH ID SUPCAR
352{
[379]353#ifdef DEBUG_SERVICE_CONF
[621]354  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
[379]355#endif
[1]356  if(strcmp($3,"DataInputs")==0){
357    current_data=1;
[607]358    if(current_content!=NULL){
359      if(current_element->content==NULL){
360        addMapToMap(&current_element->content,current_content);
361      }
362      freeMap(&current_content);
363      free(current_content);
364      current_content=NULL;
365    }
366    if(current_element!=NULL){
367      if(my_service->content!=NULL && current_element->name!=NULL){
368        if(my_service->inputs==NULL){
369          my_service->inputs=dupElements(current_element);
370          my_service->inputs->next=NULL;
371          tmp_count++;
372        }
373        else{
374          addToElements(&my_service->inputs,current_element);
375        }
376        freeElements(&current_element);
377        free(current_element);
378        current_element=NULL;
379      }
380    }
[1]381  }
382  if(strcmp($3,"DataOutputs")==0){
383    current_data=2;
384  }
385  if(strcmp($3,"MetaData")==0){
[621]386    if(current_content!=NULL){
387#ifdef DEBUG_SERVICE_CONF
388      fprintf(stderr,"add current_content to current_element->content\n");
389      fprintf(stderr,"LINE %d",__LINE__);
390#endif
391      if(wait_metadata){
392        current_element->metadata=NULL;
393        addMapToMap(&current_element->metadata,current_content);
394        current_element->next=NULL;
395        current_element->defaults=NULL;
396        current_element->supported=NULL;
397      }else{
398        if(wait_mainmetadata){
399          addMapToMap(&my_service->metadata,current_content);
400        }
401      }
402
403      freeMap(&current_content);
404      free(current_content);
405      current_content=NULL;
406    }
[1]407    current_data=previous_data;
[621]408    wait_mainmetadata=false;
409    wait_metadata=false;
[1]410  }
411  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
412     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
[621]413    if(current_element->format==NULL)
414      current_element->format=zStrdup($3);
[1]415    current_content=NULL;
416  }
417  if(strcmp($3,"Default")==0){
418    current_data=previous_data;
419    if(current_element->defaults==NULL){
[9]420      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
421      current_element->defaults->content=NULL;
[1]422    }
[9]423    addMapToMap(&current_element->defaults->content,current_content);
424    freeMap(&current_content);
425    free(current_content);
[1]426    current_element->defaults->next=NULL;
427    wait_defaults=false;
428    current_content=NULL;
429    current_element->supported=NULL;
[57]430    current_element->next=NULL;
[1]431  }
432  if(strcmp($3,"Supported")==0){
433    current_data=previous_data;
434    if(current_element->supported==NULL){
[57]435      if(current_content!=NULL){
436        current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
437        current_element->supported->content=NULL;
438        addMapToMap(&current_element->supported->content,current_content);
439        freeMap(&current_content);
440        free(current_content);
441        current_element->supported->next=NULL;
442        current_content=NULL;
443      }else{
444        current_element->supported=NULL;
445        current_element->next=NULL;
446      }
[1]447    }
[9]448    else{
[57]449#ifdef DEBUG_SERVICE_CONF
[9]450      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
[1]451#endif
[57]452      addMapToIoType(&current_element->supported,current_content);
[9]453      freeMap(&current_content);
454      free(current_content);
455      current_content=NULL;
[57]456#ifdef DEBUG_SERVICE_CONF
457      dumpElements(current_element);
[9]458      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
459#endif
[1]460    }
461    current_content=NULL;
462  }
463}
464 ;
[20]465
[1]466//======================================================
467// contentetoile
468//======================================================
469// regle 43
470// ENTRE 2 BALISES
471// entre 2 balises, on peut avoir :
472// --- OUVRANTE CONTENU FERMANTE (recursivement !)
473// --- DU TEXTE quelconque
474// --- COMMENTS
475// --- DES PROCESSES INSTRUCTIONS
476// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
477// --- EPSILON
478// ### et/ou tout ca a la suite en nombre indeterminé
479// ### donc c'est un operateur etoile (*)
480//======================================================
481contentetoile
482: contentetoile element           {}
483 | contentetoile PIERROR                  {srerror("processing instruction <?xml ?> impossible\n");}
484 | contentetoile PI                       {}
485///// on filtre les commentaires | contentetoile comment              {}
486 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
487 | contentetoile pair {}
488 | contentetoile processid {}
489 | contentetoile texteinterbalise         {}
490 | contentetoile CDATA {} 
491 | {/* Epsilon */}
492 ;
[20]493
[1]494// texteinterbalise
495// regle 14
496// DU TEXTE quelconque
497// c'est du CHARDATA
498// il y a eut un probleme avec ID,
499// on a mis des starts conditions,
500// maintenant on croise les ID dans les dbalises
501// et des CHARDATA hors des balises
502texteinterbalise
503 : CHARDATA             {}
504 ;
505
[104]506pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
[1]507| EPAIR {
508#ifdef DEBUG_SERVICE_CONF
[621]509  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
[104]510  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
511  dumpMap(current_content);
512  fflush(stderr);
[1]513#endif
[539]514  if($1!=NULL && curr_key!=NULL){
[104]515    if(current_content==NULL){
[1]516#ifdef DEBUG_SERVICE_CONF
[104]517      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]518#endif
[104]519      current_content=createMap(curr_key,$1);
[1]520#ifdef DEBUG_SERVICE_CONF
[104]521      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]522#endif
[104]523    }
524    else{
[1]525#ifdef DEBUG_SERVICE_CONF
[104]526      dumpMap(current_content);
527      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
[1]528#endif
[104]529      addToMap(current_content,curr_key,$1);
[1]530#ifdef DEBUG_SERVICE_CONF
[104]531      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
[1]532#endif   
[104]533    }
[1]534  }
535#ifdef DEBUG_SERVICE_CONF
536  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
[93]537  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[379]538  dumpMap(current_content);
[1]539  fflush(stderr);
540#endif
[9]541  if(curr_key!=NULL){
542    free(curr_key);
543    curr_key=NULL;
[1]544  }
[9]545  }
[453]546| SPAIR  { if(curr_key!=NULL) {free(curr_key);curr_key=NULL;} if($1!=NULL) curr_key=zStrdup($1);if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); }
[1]547 ;
548
549
550processid
551: ANID  {
[379]552#ifdef DEBUG_SERVICE_CONF
[621]553  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
[379]554#endif
[788]555//  if(data==-1){
556//    data=1;
557  if(::data==-1){ // knut: add namespace to avoid ambiguous symbol
558    ::data=1;   
[104]559    if($1!=NULL){
[453]560      char *cen=zStrdup($1);
[104]561      my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
562      cen[strlen(cen)-1]=0;
563      cen+=1;
564      sprintf(my_service->name,"%s",cen);
565      cen-=1;
566      free(cen);
567      my_service->content=NULL;
568      my_service->metadata=NULL;
569      my_service->inputs=NULL;
570      my_service->outputs=NULL;
571    }
[1]572  } else {
573    if(current_data==1){
574      if(my_service->content!=NULL && current_element->name!=NULL){
575        if(my_service->inputs==NULL){
576          my_service->inputs=dupElements(current_element);
[9]577          my_service->inputs->next=NULL;
[1]578          tmp_count++;
579        }
580        else{
[9]581          addToElements(&my_service->inputs,current_element);
[1]582        }
583#ifdef DEBUG_SERVICE_CONF
[9]584        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
585        dumpElements(current_element);
586        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
[1]587        dumpElements(my_service->inputs);
588#endif
[9]589        freeElements(&current_element);
[1]590        free(current_element);
591        current_element=NULL;
592#ifdef DEBUG_SERVICE_CONF
593        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
594#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;
603      }
604      if(current_element->name==NULL){
605#ifdef DEBUG_SERVICE_CONF
606        fprintf(stderr,"NAME IN %s (current - %s)\n",
607                $1,current_element->name);
608#endif
609        wait_inputs=true;
610#ifdef DEBUG_SERVICE_CONF
611        fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
612#endif
[104]613        if($1!=NULL){
[453]614          char *cen=zStrdup($1);
[104]615          current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
616          cen[strlen(cen)-1]=0;
617          cen+=1;
618          sprintf(current_element->name,"%s",cen);
619          cen-=1;
620          free(cen);
[1]621#ifdef DEBUG_SERVICE_CONF
[104]622          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]623#endif
[104]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;
[1]630#ifdef DEBUG_SERVICE_CONF
[104]631          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]632#endif
[104]633        }
[1]634      }
635    }
636    else
637      if(current_data==2){
[607]638        wait_outputs=1;
[65]639        if(wait_inputs){
[57]640          if(current_element!=NULL && current_element->name!=NULL){
[65]641            if(my_service->outputs==NULL){
642              my_service->outputs=dupElements(current_element);
643              my_service->outputs->next=NULL;
[1]644            }
645            else{
646#ifdef DEBUG_SERVICE_CONF
647              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
648#endif
[65]649              addToElements(&my_service->outputs,current_element);
[1]650            }
651#ifdef DEBUG_SERVICE_CONF
652            dumpElements(current_element);
[9]653            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
[1]654#endif
655            freeElements(&current_element);
[9]656            free(current_element);
[1]657            current_element=NULL;
658#ifdef DEBUG_SERVICE_CONF
[104]659            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
[1]660#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;
669          }
670          if(current_element->name==NULL){
671#ifdef DEBUG_SERVICE_CONF
672            fprintf(stderr,"NAME OUT %s\n",$1);
[104]673            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
[1]674#endif
[104]675            if($1!=NULL){
[453]676              char *cen=zStrdup($1);
[104]677              current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
678              cen[strlen(cen)-1]=0;
679              cen+=1;
680              sprintf(current_element->name,"%s",cen);
681              cen-=1;
682              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;
689            }
[1]690          }
[65]691
[1]692          current_content=NULL;
693        }
694        else
[65]695          if(current_element!=NULL && current_element->name!=NULL){
696            if(my_service->outputs==NULL)
697              my_service->outputs=dupElements(current_element);
698            else
699              addToElements(&my_service->outputs,current_element);
[92]700#ifdef DEBUG_SERVICE_CONF
[65]701            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
702            dupElements(current_element);
[92]703#endif
[65]704            freeElements(&current_element);
705            free(current_element);
706            current_element=NULL;
[379]707            current_element=(elements*)malloc(ELEMENTS_SIZE);
[453]708            char *cen=zStrdup($1);
[379]709            current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
710            cen[strlen(cen)-1]=0;
711            cen+=1;
712            sprintf(current_element->name,"%s",cen);
713            cen-=1;
714            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;
[65]721          }
722          else{
[1]723#ifdef DEBUG_SERVICE_CONF
724            fprintf(stderr,"NAME OUT %s\n",$1);
[379]725            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
[1]726#endif
[104]727            if($1!=NULL){
[453]728              char *cen=zStrdup($1);
[379]729              current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
[104]730              cen[strlen(cen)-1]=0;
[9]731#ifdef DEBUG
[104]732              fprintf(stderr,"tmp %s\n",cen);
[9]733#endif
[104]734              cen+=1;
735              sprintf(current_element->name,"%s",cen);
736              cen-=1;
737              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;
744            }
[1]745          }
[65]746        wait_inputs=false;
[607]747        wait_outputs=1;
[65]748        //wait_outputs=true;
[1]749      }
750  }
751 }
752 ;
753
754%%
755
[607]756/**
[781]757 * Print on stderr the message and the line number of the error which occurred.
[607]758 *
759 * @param s the error message
760 */
[114]761void srerror(const char *s)
[1]762{
763  if(debug)
764    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
765}
766
767/**
[607]768 * Parse a ZCFG file and fill the service structure.
769 *
770 * @param conf the conf maps containing the main.cfg settings
771 * @param file the fullpath to the ZCFG file
772 * @param service the service structure to fill
773 * @return 0 on success, -1 on failure
[1]774 */
[465]775int getServiceFromFile(maps* conf,const char* file,service** service){
776  if(current_content!=NULL){
777    freeMap(&current_content);
778    free(current_content);
779    current_content=NULL;
780  }
[1]781#ifdef DEBUG_SERVICE_CONF
782  fprintf(stderr,"(STARTING)FREE current_element\n");
783#endif
[465]784  if(current_element!=NULL){
785    freeElements(&current_element);
786    free(current_element);
787    current_element=NULL;
788  }
[1]789  my_service=NULL;
790
791  wait_maincontent=true;
792  wait_mainmetadata=false;
793  wait_metadata=false;
794  wait_inputs=false;
795  wait_defaults=false;
796  wait_supporteds=false;
[607]797  wait_outputs=-1;
[1]798  wait_data=false;
[788]799//data=-1;
800  ::data=-1; // knut: add namespace to avoid ambiguous symbol
[1]801  previous_data=1;
802  current_data=0;
803 
804  my_service=*service;
805
806  srin = fopen(file,"r");
807  if (srin==NULL){
[503]808    setMapInMaps(conf,"lenv","message","file not found");
[9]809    return -1;
[1]810  }
811
812  int resultatYYParse = srparse() ;
[476]813
[465]814#ifdef DEBUG_SERVICE_CONF
815  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
[607]816  dumpElements(current_element);
[465]817#endif
[618]818  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
[676]819    if(current_content!=NULL){
820      addMapToMap(&current_element->content,current_content);
821    }
[607]822    if(my_service->outputs==NULL){ 
[1]823#ifdef DEBUG_SERVICE_CONF
[104]824      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
[1]825#endif
826      my_service->outputs=dupElements(current_element);
[9]827      my_service->outputs->next=NULL;
[1]828    }
829    else{
830#ifdef DEBUG_SERVICE_CONF
[104]831      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
[1]832#endif
[9]833      addToElements(&my_service->outputs,current_element);
[1]834    }
835#ifdef DEBUG_SERVICE_CONF
[104]836    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[1]837#endif
838    freeElements(&current_element);
[9]839    free(current_element);
840    current_element=NULL;
[57]841#ifdef DEBUG_SERVICE_CONF
[104]842    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[57]843#endif
[1]844  }
845  if(current_element!=NULL){
846    freeElements(&current_element);
[9]847    free(current_element);
[1]848    current_element=NULL;
849  }
[618]850  int contentOnly=false;
[1]851  if(current_content!=NULL){
[607]852    if(my_service->content==NULL){
853      addMapToMap(&my_service->content,current_content);
[618]854      contentOnly=true;
855      wait_maincontent=false;
[607]856    }
[1]857    freeMap(&current_content);
[9]858    free(current_content);
[1]859    current_content=NULL;
860  }
861  fclose(srin);
862#ifdef DEBUG_SERVICE_CONF
863  dumpService(my_service);
864#endif
[618]865  if(wait_maincontent==true || (contentOnly==false && ((!wait_outputs && current_data==2 && my_service->outputs==NULL) || my_service==NULL || my_service->name==NULL || my_service->content==NULL))){
[465]866    setMapInMaps(conf,"lenv","message",srlval.chaine);
867#ifndef WIN32
868    srlex_destroy();
869#endif
870    return -1;
871  }
872  else
873    *service=my_service;
[1]874
[216]875#ifndef WIN32
[9]876  srlex_destroy();
[216]877#endif
[1]878  return resultatYYParse;
879}
Note: See TracBrowser for help on using the repository browser.

Search

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