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

Last change on this file was 917, checked in by djay, 5 years ago

Merge prototype-v0 branch in trunk

File size: 27.5 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
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.
23 */
24%{
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_mainap=false;
36static bool wait_metadata=false;
37static bool wait_ap=false;
38static bool wait_nested=false;
39static bool wait_inputs=false;
40static bool wait_defaults=false;
41static bool wait_supporteds=false;
42static bool wait_outputs=false;
43static bool wait_data=false;
44static service* my_service=NULL;
45static map* current_content=NULL;
46static elements* current_element=NULL;
47static char* curr_key;
48static int debug=0;
49static int data=-1;
50static int previous_data=0;
51static int current_data=0;
52static int nested_level=0;
53// namespace
54using namespace std;
55
56// srerror
57void srerror(const char *s);
58
59// usage ()
60void usage(void) ;
61
62// srdebug
63extern int srdebug;
64
65extern char srtext[];
66
67// srlineno
68extern int srlineno;
69
70// srin
71extern FILE* srin;
72
73// srlex
74extern int srlex(void);
75extern int srlex_destroy(void);
76
77%}
78
79
80
81%union
82{char * s;char* chaine;char* key;char* val;}
83
84// jetons //
85%token <s> ID
86%token <s> CHAINE
87
88%token INFCAR SUPCAR
89
90/* / = a1  texte "texte" */
91%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID
92%type <chaine> PAIR
93%type <chaine> EPAIR
94%type <chaine> SPAIR
95
96/* <!-- xxx -> <? xxx yyy ?> */
97%token PI PIERROR /** COMMENT **/
98
99/* <!-- xxx -> <? xxx yyy ?> */
100%token ERREURGENERALE CDATA WHITESPACE NEWLINE
101%type <s> STag
102%type <s> ETag
103%type <s> ANID
104
105// % start
106
107%%
108// document
109// regle 1
110// on est a la racine du fichier xml
111document
112 : miscetoile element miscetoile {}
113 | contentetoile processid contentetoile document {}
114 ;
115
116miscetoile
117 : miscetoile PIERROR {  srerror("processing instruction beginning with <?xml ?> impossible\n");}
118 | miscetoile PI {}
119 | {}
120 ;
121// element
122// regle 39
123// OUVRANTE CONTENU FERMANTE obligatoirement
124// ou neutre
125// on ne peut pas avoir Epsilon
126// un fichier xml ne peut pas etre vide ou seulement avec un prolog
127element
128 : STag contentetoile ETag     
129{
130}
131
132// pour neutre
133// on a rien a faire, meme pas renvoyer l identificateur de balise
134// vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
135 | EmptyElemTag          {}
136 ;
137
138// STag
139// regle 40
140// BALISE OUVRANTE
141// on est obligé de faire appel a infcar et supcar
142// pour acceder aux start conditions DANSBALISE et INITIAL
143STag
144: INFCAR ID Attributeetoile SUPCAR
145{
146#ifdef DEBUG_SERVICE_CONF
147  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
148  fflush(stderr);
149  dumpMap(current_content);
150#endif
151  if(my_service->content==NULL && current_content!=NULL){
152#ifdef DEBUG_SERVICE_CONF
153    fprintf(stderr,"NO CONTENT\n");
154#endif
155    addMapToMap(&my_service->content,current_content);
156    freeMap(&current_content);
157    free(current_content);
158    current_content=NULL;
159    my_service->metadata=NULL;
160    my_service->additional_parameters=NULL;
161    wait_maincontent=false;
162  }
163  if(strncasecmp($2,"EndNested",9)==0){
164#ifdef DEBUG_SERVICE_CONF
165    fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__);
166    fflush(stderr);
167#endif
168    nested_level-=1;
169    if(nested_level==0){
170      wait_nested=false;
171    }
172  }
173
174  if(strncasecmp($2,"DataInputs",10)==0){
175    if(current_element==NULL){
176#ifdef DEBUG_SERVICE_CONF
177      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
178#endif
179      freeElements(&current_element);
180      free(current_element);
181#ifdef DEBUG_SERVICE_CONF
182      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
183#endif
184      current_element=NULL;
185      current_element=createEmptyElements();
186    }
187    wait_inputs=true;
188    current_data=1;
189    previous_data=1;
190  }
191  else
192    if(strncasecmp($2,"DataOutputs",11)==0){
193      if(wait_inputs==true){
194#ifdef DEBUG_SERVICE_CONF
195        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
196        fprintf(stderr,"CURRENT_ELEMENT\n");
197        dumpElements(current_element);
198        fprintf(stderr,"SERVICE INPUTS\n");
199        dumpElements(my_service->inputs);
200        dumpService(my_service);
201#endif 
202        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
203          my_service->inputs=dupElements(current_element);
204          my_service->inputs->next=NULL;
205          freeElements(&current_element);
206        }
207        else if(current_element!=NULL && current_element->name!=NULL){
208          addToElements(&my_service->inputs,current_element);
209          freeElements(&current_element);
210        }
211#ifdef DEBUG_SERVICE_CONF
212        fprintf(stderr,"CURRENT_ELEMENT\n");
213        dumpElements(current_element);
214        fprintf(stderr,"SERVICE INPUTS\n");
215        dumpElements(my_service->inputs);
216        fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
217#endif
218        free(current_element);
219        current_element=NULL;
220        wait_inputs=false;
221      }
222      if(current_element==NULL){
223#ifdef DEBUG_SERVICE_CONF
224        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
225        fflush(stderr);
226#endif
227        current_element=createEmptyElements();
228      }
229      wait_outputs=1;
230      current_data=2;
231      previous_data=2;
232    }
233    else
234      if(strncasecmp($2,"MetaData",8)==0 ||
235         strncasecmp($2,"AdditionalParameters",8)==0){
236        if(strncasecmp($2,"AdditionalParameters",8)==0){
237          previous_data=current_data;
238          current_data=4;
239          if(current_element!=NULL){
240#ifdef DEBUG_SERVICE_CONF
241            fprintf(stderr,"add current_content to current_element->content\n");
242            fprintf(stderr,"LINE %d",__LINE__);
243#endif
244            if(wait_mainmetadata)
245              addMapToMap(&my_service->metadata,current_content);
246            else
247              if(wait_metadata)
248                addMapToMap(&current_element->metadata,current_content);
249              else
250                addMapToMap(&current_element->content,current_content);         
251            freeMap(&current_content);
252            free(current_content);
253            if(previous_data==1 || previous_data==2)
254              wait_ap=true;
255            else
256              wait_mainap=true;
257          }
258          else{
259            if(previous_data==1 || previous_data==2)
260              wait_ap=true;
261            else
262              wait_mainap=true;
263          }
264        }else{
265          previous_data=current_data;
266          current_data=3;
267          if(current_element!=NULL){
268#ifdef DEBUG_SERVICE_CONF
269            fprintf(stderr,"add current_content to current_element->content\n");
270            fprintf(stderr,"LINE %d",__LINE__);
271#endif
272            addMapToMap(&current_element->content,current_content);
273            freeMap(&current_content);
274            free(current_content);
275            if(previous_data==1 || previous_data==2)
276              wait_metadata=true;
277            else
278              wait_mainmetadata=true;
279          }
280          else{
281            if(previous_data==1 || previous_data==2)
282              wait_metadata=true;
283            else
284              wait_mainmetadata=true;
285          }
286        }
287        current_content=NULL;
288      }
289      else
290        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
291           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
292           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
293          current_data=4;
294          addMapToMap(&current_element->content,current_content);
295          freeMap(&current_content);
296          free(current_content);
297          current_element->next=NULL;
298          if($2!=NULL)
299            current_element->format=zStrdup($2);
300          current_element->defaults=NULL;
301          current_element->supported=NULL;
302          current_element->child=NULL;
303          current_content=NULL;
304        }
305        else
306          if(strncasecmp($2,"Default",7)==0){
307            wait_defaults=true;
308            current_data=5;
309          }
310          else
311            if(strncasecmp($2,"Supported",9)==0){
312              wait_supporteds=true;
313              if(wait_defaults==true){
314                defaultsc++;
315              }
316              current_data=5;
317            }
318#ifdef DEBUG_SERVICE_CONF
319  fprintf(stderr,"* Identifiant : %s\n",$2);
320  fflush(stderr);
321#endif
322}
323 ;
324
325// Attributeetoile
326// regle 41
327// une liste qui peut etre vide d'attributs
328// utiliser la récursivité a gauche
329Attributeetoile
330: Attributeetoile attribute  {}
331 |                                {/* Epsilon */}
332 ;
333
334// attribute
335// regle 41
336// un attribut est compose d'un identifiant
337// d'un "="
338// et d'une définition de chaine de caractere
339// ( "xxx" ou 'xxx' )
340attribute
341 : ID Eq ATTVALUE               
342{
343#ifdef DEBUG_SERVICE_CONF
344  printf ("attribute : %s\n",$1) ;
345#endif
346}
347 ;
348
349// EmptyElemTag
350// regle 44
351// ICI ON DEFINIT NEUTRE
352// on ne renvoie pas de char*
353// parce qu'il n'y a pas de comparaisons a faire
354// avec un identifiant d'une balise jumelle
355EmptyElemTag
356 : INFCAR ID Attributeetoile SLASH SUPCAR       {
357#ifdef DEBUG_SERVICE_CONF
358  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
359#endif
360   if(strncasecmp($2,"Default",7)==0){
361     wait_defaults=false;
362     current_data=previous_data;
363     if(current_element->defaults==NULL){
364       current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
365       current_element->defaults->content=NULL;
366     }
367     addMapToMap(&current_element->defaults->content,current_content);
368     freeMap(&current_content);
369     free(current_content);
370     current_element->defaults->next=NULL;
371     wait_defaults=false;
372     current_content=NULL;
373     current_element->supported=NULL;
374     current_element->child=NULL;
375     current_element->next=NULL;
376   }
377   if(strncasecmp($2,"EndNested",9)==0){
378     if(current_data==1){
379       elements* cursor=my_service->inputs;
380       while(cursor->next!=NULL)
381         cursor=cursor->next;
382       if(nested_level>1){
383         for(int j=0;j<nested_level-1;j++){
384           cursor=cursor->child;
385           while(cursor->next!=NULL)
386             cursor=cursor->next;
387         }
388       }
389       if(cursor->child==NULL){
390         cursor->child=dupElements(current_element);
391       }else{
392         addToElements(&cursor->child,current_element);
393       }
394     }else{
395       if(current_element->name!=NULL){
396         elements* cursor=my_service->outputs;
397         while(cursor->next!=NULL)
398           cursor=cursor->next;
399         if(nested_level>1){
400           for(int j=0;j<nested_level-1;j++){
401             cursor=cursor->child;
402             while(cursor->next!=NULL)
403               cursor=cursor->next;
404           }
405         }
406         if(cursor->child==NULL){
407           cursor->child=dupElements(current_element);
408         }else
409           addToElements(&cursor->child,current_element);
410       }
411     }
412     freeElements(&current_element);
413     free(current_element);
414     current_element=NULL;
415     current_element=createEmptyElements();
416     nested_level-=1;
417     if(nested_level==0){
418       wait_nested=false;       
419     }
420   }
421 }
422 ;
423
424// ETag
425// BALISE FERMANTE
426// les separateurs après ID sont filtrés
427ETag
428 : INFCAR SLASH ID SUPCAR
429{
430#ifdef DEBUG_SERVICE_CONF
431  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
432#endif
433  if(strcmp($3,"DataInputs")==0){
434    current_data=1;
435    if(current_content!=NULL){
436      if(current_element->content==NULL){
437        addMapToMap(&current_element->content,current_content);
438      }
439      freeMap(&current_content);
440      free(current_content);
441      current_content=NULL;
442    }
443    if(current_element!=NULL){
444      if(my_service->content!=NULL && current_element->name!=NULL){
445        if(my_service->inputs==NULL){
446          my_service->inputs=dupElements(current_element);
447          my_service->inputs->next=NULL;
448          tmp_count++;
449        }
450        else{
451          addToElements(&my_service->inputs,current_element);
452        }
453        freeElements(&current_element);
454        free(current_element);
455        current_element=NULL;
456      }
457    }
458  }
459  if(strcmp($3,"DataOutputs")==0){
460    current_data=2;
461  } 
462  if(strcmp($3,"AdditionalParameters")==0){
463    if(current_content!=NULL){
464#ifdef DEBUG_SERVICE_CONF
465      fprintf(stderr,"add current_content to current_element->content\n");
466      fprintf(stderr,"LINE %d",__LINE__);
467#endif
468      if(wait_ap){
469        current_element->additional_parameters=NULL;
470        addMapToMap(&current_element->additional_parameters,current_content);
471        current_element->next=NULL;
472        current_element->defaults=NULL;
473        current_element->supported=NULL;
474        current_element->child=NULL;
475      }else{
476        if(wait_mainap){
477          addMapToMap(&my_service->additional_parameters,current_content);
478        }
479      }
480
481      freeMap(&current_content);
482      free(current_content);
483      current_content=NULL;
484    }
485    current_data=previous_data;
486    wait_mainap=false;
487    wait_ap=false;
488  }
489  if(strcmp($3,"MetaData")==0){
490    if(current_content!=NULL){
491#ifdef DEBUG_SERVICE_CONF
492      fprintf(stderr,"add current_content to current_element->content\n");
493      fprintf(stderr,"LINE %d",__LINE__);
494#endif
495      if(wait_metadata){
496        current_element->metadata=NULL;
497        addMapToMap(&current_element->metadata,current_content);
498        current_element->next=NULL;
499        current_element->defaults=NULL;
500        current_element->supported=NULL;
501        current_element->child=NULL;
502      }else{
503        if(wait_mainmetadata){
504          addMapToMap(&my_service->metadata,current_content);
505        }
506      }
507
508      freeMap(&current_content);
509      free(current_content);
510      current_content=NULL;
511    }
512    current_data=previous_data;
513    wait_mainmetadata=false;
514    wait_metadata=false;
515  }
516  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
517     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
518    if(current_element->format==NULL)
519      current_element->format=zStrdup($3);
520    current_content=NULL;
521  }
522  if(strcmp($3,"Default")==0){
523    current_data=previous_data;
524    if(current_element->defaults==NULL){
525      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
526      current_element->defaults->content=NULL;
527    }
528    addMapToMap(&current_element->defaults->content,current_content);
529    freeMap(&current_content);
530    free(current_content);
531    current_element->defaults->next=NULL;
532    wait_defaults=false;
533    current_content=NULL;
534    current_element->supported=NULL;
535    current_element->child=NULL;
536    current_element->next=NULL;
537  }
538  if(strcmp($3,"Supported")==0){
539    current_data=previous_data;
540    if(current_element->supported==NULL){
541      if(current_content!=NULL){
542        current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
543        current_element->supported->content=NULL;
544        addMapToMap(&current_element->supported->content,current_content);
545        freeMap(&current_content);
546        free(current_content);
547        current_element->supported->next=NULL;
548        current_content=NULL;
549      }else{
550        current_element->supported=NULL;
551        current_element->child=NULL;
552        current_element->next=NULL;
553      }
554    }
555    else{
556#ifdef DEBUG_SERVICE_CONF
557      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
558#endif
559      addMapToIoType(&current_element->supported,current_content);
560      freeMap(&current_content);
561      free(current_content);
562      current_content=NULL;
563#ifdef DEBUG_SERVICE_CONF
564      dumpElements(current_element);
565      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
566#endif
567    }
568    current_content=NULL;
569  }
570}
571 ;
572
573//======================================================
574// contentetoile
575//======================================================
576// regle 43
577// ENTRE 2 BALISES
578// entre 2 balises, on peut avoir :
579// --- OUVRANTE CONTENU FERMANTE (recursivement !)
580// --- DU TEXTE quelconque
581// --- COMMENTS
582// --- DES PROCESSES INSTRUCTIONS
583// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
584// --- EPSILON
585// ### et/ou tout ca a la suite en nombre indeterminé
586// ### donc c'est un operateur etoile (*)
587//======================================================
588contentetoile
589: contentetoile element           {}
590 | contentetoile PIERROR                  {srerror("processing instruction <?xml ?> impossible\n");}
591 | contentetoile PI                       {}
592///// on filtre les commentaires | contentetoile comment              {}
593 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
594 | contentetoile pair {}
595 | contentetoile processid {}
596 | contentetoile texteinterbalise         {}
597 | contentetoile CDATA {} 
598 | {/* Epsilon */}
599 ;
600
601// texteinterbalise
602// regle 14
603// DU TEXTE quelconque
604// c'est du CHARDATA
605// il y a eut un probleme avec ID,
606// on a mis des starts conditions,
607// maintenant on croise les ID dans les dbalises
608// et des CHARDATA hors des balises
609texteinterbalise
610 : CHARDATA             {}
611 ;
612
613pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
614| EPAIR {
615#ifdef DEBUG_SERVICE_CONF
616  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
617  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
618  dumpMap(current_content);
619  fflush(stderr);
620#endif
621  if($1!=NULL && curr_key!=NULL){
622    if(current_content==NULL){
623#ifdef DEBUG_SERVICE_CONF
624      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
625#endif
626      current_content=createMap(curr_key,$1);
627#ifdef DEBUG_SERVICE_CONF
628      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
629#endif
630    }
631    else{
632#ifdef DEBUG_SERVICE_CONF
633      dumpMap(current_content);
634      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
635#endif
636      addToMap(current_content,curr_key,$1);
637#ifdef DEBUG_SERVICE_CONF
638      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
639#endif   
640    }
641  }
642#ifdef DEBUG_SERVICE_CONF
643  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
644  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
645  dumpMap(current_content);
646  fflush(stderr);
647#endif
648  if(curr_key!=NULL){
649    free(curr_key);
650    curr_key=NULL;
651  }
652  }
653| 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"); }
654 ;
655
656
657processid
658: ANID  {
659#ifdef DEBUG_SERVICE_CONF
660  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
661#endif
662  if(::data==-1){ // knut: add namespace to avoid ambiguous symbol
663    ::data=1;   
664    if($1!=NULL){
665      char *cen=zStrdup($1);
666      cen[strlen(cen)-1]=0;
667      cen+=1;
668      setServiceName(&my_service,cen);
669      cen-=1;
670      free(cen);
671    }
672  } else {
673    if(current_data==1){
674      if(my_service->content!=NULL && current_element->name!=NULL){
675        if(my_service->inputs==NULL){
676          my_service->inputs=dupElements(current_element);
677          my_service->inputs->next=NULL;
678          tmp_count++;
679        }
680        else{
681          if(wait_nested){
682            elements* cursor=my_service->inputs;
683            while(cursor->next!=NULL)
684              cursor=cursor->next;
685            if(nested_level>1){
686              for(int j=0;j<nested_level-1;j++){
687                cursor=cursor->child;
688                while(cursor->next!=NULL)
689                  cursor=cursor->next;
690              }
691            }
692            if(cursor->child==NULL){
693              cursor->child=dupElements(current_element);
694            }else{
695              addToElements(&cursor->child,current_element);
696            }
697          }else
698            addToElements(&my_service->inputs,current_element);
699        }
700        if(current_element->format==NULL){
701          wait_nested=true;
702          nested_level+=1;
703          if(current_content!=NULL){
704            elements* cursor=my_service->inputs;
705            while(cursor->next!=NULL)
706              cursor=cursor->next;
707            if(nested_level>1){
708              for(int j=0;j<nested_level-1;j++){
709                cursor=cursor->child;
710                while(cursor->next!=NULL)
711                  cursor=cursor->next;
712              }
713            }
714            addMapToMap(&cursor->content,current_content);
715            freeMap(&current_content);
716            free(current_content);
717            current_content=NULL;
718          }
719        }
720#ifdef DEBUG_SERVICE_CONF
721        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
722        dumpElements(current_element);
723        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
724        dumpElements(my_service->inputs);
725#endif
726        freeElements(&current_element);
727        free(current_element);
728        current_element=NULL;
729#ifdef DEBUG_SERVICE_CONF
730        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
731#endif
732        current_element=createEmptyElements();
733      }
734      if(current_element->name==NULL){
735#ifdef DEBUG_SERVICE_CONF
736        fprintf(stderr,"NAME IN %s (current - %s)\n",
737                $1,current_element->name);
738#endif
739        wait_inputs=true;
740#ifdef DEBUG_SERVICE_CONF
741        fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
742#endif
743        if($1!=NULL){
744          char *cen=zStrdup($1);
745          cen[strlen(cen)-1]=0;
746          cen+=1;
747          setElementsName(&current_element,cen);
748          cen-=1;
749          free(cen);
750#ifdef DEBUG_SERVICE_CONF
751          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
752#endif
753#ifdef DEBUG_SERVICE_CONF
754          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
755#endif
756        }
757      }
758    }
759    else
760      if(current_data==2){
761        wait_outputs=1;
762        if(wait_inputs){
763          if(current_element!=NULL && current_element->name!=NULL){
764            if(my_service->outputs==NULL){
765              my_service->outputs=dupElements(current_element);
766              my_service->outputs->next=NULL;
767            }
768            else{
769#ifdef DEBUG_SERVICE_CONF
770              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
771#endif
772              addToElements(&my_service->outputs,current_element);
773            }
774#ifdef DEBUG_SERVICE_CONF
775            dumpElements(current_element);
776            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
777#endif
778            freeElements(&current_element);
779            free(current_element);
780            current_element=NULL;
781#ifdef DEBUG_SERVICE_CONF
782            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
783#endif
784            current_element=createEmptyElements();
785          }
786          if(current_element->name==NULL){
787#ifdef DEBUG_SERVICE_CONF
788            fprintf(stderr,"NAME OUT %s\n",$1);
789            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
790#endif
791            if($1!=NULL){
792              char *cen=zStrdup($1);
793              cen[strlen(cen)-1]=0;
794              cen+=1;
795              setElementsName(&current_element,cen);
796              cen-=1;
797              free(cen);
798            }
799          }
800
801          current_content=NULL;
802        }
803        else
804          if(current_element!=NULL && current_element->name!=NULL){
805            if(my_service->outputs==NULL)
806              my_service->outputs=dupElements(current_element);
807            else{
808              if(wait_nested){
809                elements* cursor=my_service->outputs;
810                while(cursor->next!=NULL)
811                  cursor=cursor->next;
812                if(nested_level>1){
813                  for(int j=0;j<nested_level-1;j++){
814                    cursor=cursor->child;
815                    while(cursor->next!=NULL)
816                      cursor=cursor->next;
817                  }
818                }
819                if(cursor->child==NULL){
820                  cursor->child=dupElements(current_element);
821                }else
822                  addToElements(&cursor->child,current_element);
823              }else
824                addToElements(&my_service->outputs,current_element);
825            }
826            if(current_element->format==NULL){
827              wait_nested=true;
828              nested_level+=1;
829              if(current_content!=NULL){
830                elements* cursor=my_service->outputs;
831                while(cursor->next!=NULL)
832                  cursor=cursor->next;
833                if(nested_level>1){
834                  for(int j=0;j<nested_level-1;j++){
835                    cursor=cursor->child;
836                    while(cursor->next!=NULL)
837                      cursor=cursor->next;
838                  }
839                }
840                addMapToMap(&cursor->content,current_content);
841                freeMap(&current_content);
842                free(current_content);
843                current_content=NULL;
844              }
845            }
846
847#ifdef DEBUG_SERVICE_CONF
848            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
849            dupElements(current_element);
850#endif
851            freeElements(&current_element);
852            free(current_element);
853            current_element=NULL;
854           
855            char *cen=zStrdup($1);
856            cen[strlen(cen)-1]=0;
857            cen+=1;
858            current_element=createElements(cen);
859            cen-=1;
860            free(cen);
861          }
862          else{
863#ifdef DEBUG_SERVICE_CONF
864            fprintf(stderr,"NAME OUT %s\n",$1);
865            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
866#endif
867            if($1!=NULL){
868              char *cen=zStrdup($1);
869              cen[strlen(cen)-1]=0;
870#ifdef DEBUG
871              fprintf(stderr,"tmp %s\n",cen);
872#endif
873              cen+=1;
874              setElementsName(&current_element,cen);
875              cen-=1;
876              free(cen);
877            }
878          }
879        wait_inputs=false;
880        wait_outputs=1;
881        //wait_outputs=true;
882      }
883  }
884 }
885 ;
886
887%%
888
889/**
890 * Print on stderr the message and the line number of the error which occurred.
891 *
892 * @param s the error message
893 */
894void srerror(const char *s)
895{
896  if(debug)
897    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
898}
899
900/**
901 * Parse a ZCFG file and fill the service structure.
902 *
903 * @param conf the conf maps containing the main.cfg settings
904 * @param file the fullpath to the ZCFG file
905 * @param service the service structure to fill
906 * @return 0 on success, -1 on failure
907 */
908int getServiceFromFile(maps* conf,const char* file,service** service){
909  if(current_content!=NULL){
910    freeMap(&current_content);
911    free(current_content);
912    current_content=NULL;
913  }
914#ifdef DEBUG_SERVICE_CONF
915  fprintf(stderr,"(STARTING)FREE current_element %s\n",file);
916#endif
917  fflush(stderr);
918  fflush(stdout);
919  if(current_element!=NULL){
920    freeElements(&current_element);
921    free(current_element);
922    current_element=NULL;
923  }
924  my_service=NULL;
925
926  wait_maincontent=true;
927  wait_mainmetadata=false;
928  wait_metadata=false;
929  wait_mainap=false;
930  wait_ap=false;
931  wait_inputs=false;
932  wait_defaults=false;
933  wait_supporteds=false;
934  wait_outputs=-1;
935  wait_data=false;
936  wait_nested=false;
937//data=-1;
938  ::data=-1; // knut: add namespace to avoid ambiguous symbol
939  previous_data=1;
940  current_data=0;
941 
942  my_service=*service;
943
944  srin = fopen(file,"r");
945  if (srin==NULL){
946    setMapInMaps(conf,"lenv","message","file not found");
947    return -1;
948  }
949
950  int resultatYYParse = srparse() ;
951
952#ifdef DEBUG_SERVICE_CONF
953  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
954  dumpElements(current_element);
955#endif
956  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
957    if(current_content!=NULL){
958      addMapToMap(&current_element->content,current_content);
959    }
960    if(my_service->outputs==NULL){ 
961#ifdef DEBUG_SERVICE_CONF
962      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
963#endif
964      my_service->outputs=dupElements(current_element);
965      my_service->outputs->next=NULL;
966    }
967    else{
968#ifdef DEBUG_SERVICE_CONF
969      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
970#endif
971      if(wait_nested){
972        elements* cursor=my_service->outputs;
973        while(cursor->next!=NULL)
974          cursor=cursor->next;
975        if(nested_level>1){
976          for(int j=0;j<nested_level-1;j++){
977            cursor=cursor->child;
978            while(cursor->next!=NULL)
979              cursor=cursor->next;
980          }
981        }
982        if(cursor->child==NULL){
983          cursor->child=dupElements(current_element);
984        }else
985          addToElements(&cursor->child,current_element);
986      }else
987        addToElements(&my_service->outputs,current_element);
988    }
989#ifdef DEBUG_SERVICE_CONF
990    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
991#endif
992    freeElements(&current_element);
993    free(current_element);
994    current_element=NULL;
995#ifdef DEBUG_SERVICE_CONF
996    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
997#endif
998  }
999  if(current_element!=NULL){
1000    freeElements(&current_element);
1001    free(current_element);
1002    current_element=NULL;
1003  }
1004  int contentOnly=false;
1005  if(current_content!=NULL){
1006    if(my_service->content==NULL){
1007      addMapToMap(&my_service->content,current_content);
1008      contentOnly=true;
1009      wait_maincontent=false;
1010    }
1011    freeMap(&current_content);
1012    free(current_content);
1013    current_content=NULL;
1014  }
1015  fclose(srin);
1016#ifdef DEBUG_SERVICE_CONF
1017  dumpService(my_service);
1018#endif
1019  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))){
1020    setMapInMaps(conf,"lenv","message",srlval.chaine);
1021#ifndef WIN32
1022    srlex_destroy();
1023#endif
1024    return -1;
1025  }
1026  else
1027    *service=my_service;
1028
1029#ifndef WIN32
1030  srlex_destroy();
1031#endif
1032  return resultatYYParse;
1033}
Note: See TracBrowser for help on using the repository browser.

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