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

Last change on this file since 723 was 676, checked in by djay, 9 years ago

Move createRegistry function to server_internal. Add the utils/registry service.

File size: 24.1 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
113 : miscetoile PIERROR {  srerror("processing instruction begining with <?xml ?> impossible\n");}
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
[1]555  if(data==-1){
556    data=1;
[104]557    if($1!=NULL){
[453]558      char *cen=zStrdup($1);
[104]559      my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
560      cen[strlen(cen)-1]=0;
561      cen+=1;
562      sprintf(my_service->name,"%s",cen);
563      cen-=1;
564      free(cen);
565      my_service->content=NULL;
566      my_service->metadata=NULL;
567      my_service->inputs=NULL;
568      my_service->outputs=NULL;
569    }
[1]570  } else {
571    if(current_data==1){
572      if(my_service->content!=NULL && current_element->name!=NULL){
573        if(my_service->inputs==NULL){
574          my_service->inputs=dupElements(current_element);
[9]575          my_service->inputs->next=NULL;
[1]576          tmp_count++;
577        }
578        else{
[9]579          addToElements(&my_service->inputs,current_element);
[1]580        }
581#ifdef DEBUG_SERVICE_CONF
[9]582        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
583        dumpElements(current_element);
584        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
[1]585        dumpElements(my_service->inputs);
586#endif
[9]587        freeElements(&current_element);
[1]588        free(current_element);
589        current_element=NULL;
590#ifdef DEBUG_SERVICE_CONF
591        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
592#endif
593        current_element=(elements*)malloc(ELEMENTS_SIZE);
594        current_element->name=NULL;
595        current_element->content=NULL;
596        current_element->metadata=NULL;
597        current_element->format=NULL;
598        current_element->defaults=NULL;
599        current_element->supported=NULL;
600        current_element->next=NULL;
601      }
602      if(current_element->name==NULL){
603#ifdef DEBUG_SERVICE_CONF
604        fprintf(stderr,"NAME IN %s (current - %s)\n",
605                $1,current_element->name);
606#endif
607        wait_inputs=true;
608#ifdef DEBUG_SERVICE_CONF
609        fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
610#endif
[104]611        if($1!=NULL){
[453]612          char *cen=zStrdup($1);
[104]613          current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
614          cen[strlen(cen)-1]=0;
615          cen+=1;
616          sprintf(current_element->name,"%s",cen);
617          cen-=1;
618          free(cen);
[1]619#ifdef DEBUG_SERVICE_CONF
[104]620          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]621#endif
[104]622          current_element->content=NULL;
623          current_element->metadata=NULL;
624          current_element->format=NULL;
625          current_element->defaults=NULL;
626          current_element->supported=NULL;
627          current_element->next=NULL;
[1]628#ifdef DEBUG_SERVICE_CONF
[104]629          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]630#endif
[104]631        }
[1]632      }
633    }
634    else
635      if(current_data==2){
[607]636        wait_outputs=1;
[65]637        if(wait_inputs){
[57]638          if(current_element!=NULL && current_element->name!=NULL){
[65]639            if(my_service->outputs==NULL){
640              my_service->outputs=dupElements(current_element);
641              my_service->outputs->next=NULL;
[1]642            }
643            else{
644#ifdef DEBUG_SERVICE_CONF
645              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
646#endif
[65]647              addToElements(&my_service->outputs,current_element);
[1]648            }
649#ifdef DEBUG_SERVICE_CONF
650            dumpElements(current_element);
[9]651            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
[1]652#endif
653            freeElements(&current_element);
[9]654            free(current_element);
[1]655            current_element=NULL;
656#ifdef DEBUG_SERVICE_CONF
[104]657            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
[1]658#endif
659            current_element=(elements*)malloc(ELEMENTS_SIZE);
660            current_element->name=NULL;
661            current_element->content=NULL;
662            current_element->metadata=NULL;
663            current_element->format=NULL;
664            current_element->defaults=NULL;
665            current_element->supported=NULL;
666            current_element->next=NULL;
667          }
668          if(current_element->name==NULL){
669#ifdef DEBUG_SERVICE_CONF
670            fprintf(stderr,"NAME OUT %s\n",$1);
[104]671            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
[1]672#endif
[104]673            if($1!=NULL){
[453]674              char *cen=zStrdup($1);
[104]675              current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
676              cen[strlen(cen)-1]=0;
677              cen+=1;
678              sprintf(current_element->name,"%s",cen);
679              cen-=1;
680              free(cen);
681              current_element->content=NULL;
682              current_element->metadata=NULL;
683              current_element->format=NULL;
684              current_element->defaults=NULL;
685              current_element->supported=NULL;
686              current_element->next=NULL;
687            }
[1]688          }
[65]689
[1]690          current_content=NULL;
691        }
692        else
[65]693          if(current_element!=NULL && current_element->name!=NULL){
694            if(my_service->outputs==NULL)
695              my_service->outputs=dupElements(current_element);
696            else
697              addToElements(&my_service->outputs,current_element);
[92]698#ifdef DEBUG_SERVICE_CONF
[65]699            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
700            dupElements(current_element);
[92]701#endif
[65]702            freeElements(&current_element);
703            free(current_element);
704            current_element=NULL;
[379]705            current_element=(elements*)malloc(ELEMENTS_SIZE);
[453]706            char *cen=zStrdup($1);
[379]707            current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
708            cen[strlen(cen)-1]=0;
709            cen+=1;
710            sprintf(current_element->name,"%s",cen);
711            cen-=1;
712            free(cen);
713            current_element->content=NULL;
714            current_element->metadata=NULL;
715            current_element->format=NULL;
716            current_element->defaults=NULL;
717            current_element->supported=NULL;
718            current_element->next=NULL;
[65]719          }
720          else{
[1]721#ifdef DEBUG_SERVICE_CONF
722            fprintf(stderr,"NAME OUT %s\n",$1);
[379]723            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
[1]724#endif
[104]725            if($1!=NULL){
[453]726              char *cen=zStrdup($1);
[379]727              current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
[104]728              cen[strlen(cen)-1]=0;
[9]729#ifdef DEBUG
[104]730              fprintf(stderr,"tmp %s\n",cen);
[9]731#endif
[104]732              cen+=1;
733              sprintf(current_element->name,"%s",cen);
734              cen-=1;
735              free(cen);
736              current_element->content=NULL;
737              current_element->metadata=NULL;
738              current_element->format=NULL;
739              current_element->defaults=NULL;
740              current_element->supported=NULL;
741              current_element->next=NULL;
742            }
[1]743          }
[65]744        wait_inputs=false;
[607]745        wait_outputs=1;
[65]746        //wait_outputs=true;
[1]747      }
748  }
749 }
750 ;
751
752%%
753
[607]754/**
755 * Print on stderr the message and the line number of the error which occured.
756 *
757 * @param s the error message
758 */
[114]759void srerror(const char *s)
[1]760{
761  if(debug)
762    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
763}
764
765/**
[607]766 * Parse a ZCFG file and fill the service structure.
767 *
768 * @param conf the conf maps containing the main.cfg settings
769 * @param file the fullpath to the ZCFG file
770 * @param service the service structure to fill
771 * @return 0 on success, -1 on failure
[1]772 */
[465]773int getServiceFromFile(maps* conf,const char* file,service** service){
774  if(current_content!=NULL){
775    freeMap(&current_content);
776    free(current_content);
777    current_content=NULL;
778  }
[1]779#ifdef DEBUG_SERVICE_CONF
780  fprintf(stderr,"(STARTING)FREE current_element\n");
781#endif
[465]782  if(current_element!=NULL){
783    freeElements(&current_element);
784    free(current_element);
785    current_element=NULL;
786  }
[1]787  my_service=NULL;
788
789  wait_maincontent=true;
790  wait_mainmetadata=false;
791  wait_metadata=false;
792  wait_inputs=false;
793  wait_defaults=false;
794  wait_supporteds=false;
[607]795  wait_outputs=-1;
[1]796  wait_data=false;
797  data=-1;
798  previous_data=1;
799  current_data=0;
800 
801  my_service=*service;
802
803  srin = fopen(file,"r");
804  if (srin==NULL){
[503]805    setMapInMaps(conf,"lenv","message","file not found");
[9]806    return -1;
[1]807  }
808
809  int resultatYYParse = srparse() ;
[476]810
[465]811#ifdef DEBUG_SERVICE_CONF
812  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
[607]813  dumpElements(current_element);
[465]814#endif
[618]815  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
[676]816    if(current_content!=NULL){
817      addMapToMap(&current_element->content,current_content);
818    }
[607]819    if(my_service->outputs==NULL){ 
[1]820#ifdef DEBUG_SERVICE_CONF
[104]821      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
[1]822#endif
823      my_service->outputs=dupElements(current_element);
[9]824      my_service->outputs->next=NULL;
[1]825    }
826    else{
827#ifdef DEBUG_SERVICE_CONF
[104]828      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
[1]829#endif
[9]830      addToElements(&my_service->outputs,current_element);
[1]831    }
832#ifdef DEBUG_SERVICE_CONF
[104]833    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[1]834#endif
835    freeElements(&current_element);
[9]836    free(current_element);
837    current_element=NULL;
[57]838#ifdef DEBUG_SERVICE_CONF
[104]839    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[57]840#endif
[1]841  }
842  if(current_element!=NULL){
843    freeElements(&current_element);
[9]844    free(current_element);
[1]845    current_element=NULL;
846  }
[618]847  int contentOnly=false;
[1]848  if(current_content!=NULL){
[607]849    if(my_service->content==NULL){
850      addMapToMap(&my_service->content,current_content);
[618]851      contentOnly=true;
852      wait_maincontent=false;
[607]853    }
[1]854    freeMap(&current_content);
[9]855    free(current_content);
[1]856    current_content=NULL;
857  }
858  fclose(srin);
859#ifdef DEBUG_SERVICE_CONF
860  dumpService(my_service);
861#endif
[618]862  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]863    setMapInMaps(conf,"lenv","message",srlval.chaine);
864#ifndef WIN32
865    srlex_destroy();
866#endif
867    return -1;
868  }
869  else
870    *service=my_service;
[1]871
[216]872#ifndef WIN32
[9]873  srlex_destroy();
[216]874#endif
[1]875  return resultatYYParse;
876}
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