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
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_metadata=false;
36static bool wait_inputs=false;
37static bool wait_defaults=false;
38static bool wait_supporteds=false;
39static bool wait_outputs=false;
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
53void srerror(const char *s);
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);
71extern int srlex_destroy(void);
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
83
84%token INFCAR SUPCAR
85
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
91
92/* <!-- xxx -> <? xxx yyy ?> */
93%token PI PIERROR /** COMMENT **/
94
95/* <!-- xxx -> <? xxx yyy ?> */
96%token ERREURGENERALE CDATA WHITESPACE NEWLINE
97%type <s> STag
98%type <s> ETag
99%type <s> ANID
100
101// % start
102
103%%
104// document
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}
127
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 ;
133
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{
142#ifdef DEBUG_SERVICE_CONF
143  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
144  fflush(stderr);
145  dumpMap(current_content);
146#endif
147  if(my_service->content==NULL){
148#ifdef DEBUG_SERVICE_CONF
149    fprintf(stderr,"NO CONTENT\n");
150#endif
151    addMapToMap(&my_service->content,current_content);
152    freeMap(&current_content);
153    free(current_content);
154    current_content=NULL;
155    my_service->metadata=NULL;
156    wait_maincontent=false;
157  }
158  if(strncasecmp($2,"DataInputs",10)==0){
159    if(current_element==NULL){
160#ifdef DEBUG_SERVICE_CONF
161      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
162#endif
163      freeElements(&current_element);
164      free(current_element);
165#ifdef DEBUG_SERVICE_CONF
166      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
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;
176      current_element->child=NULL;
177      current_element->next=NULL;
178    }
179    wait_inputs=true;
180    current_data=1;
181    previous_data=1;
182  }
183  else
184    if(strncasecmp($2,"DataOutputs",11)==0){
185      if(wait_inputs==true){
186#ifdef DEBUG_SERVICE_CONF
187        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
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);
193#endif 
194        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
195          my_service->inputs=dupElements(current_element);
196          my_service->inputs->next=NULL;
197          freeElements(&current_element);
198        }
199        else if(current_element!=NULL && current_element->name!=NULL){
200          addToElements(&my_service->inputs,current_element);
201          freeElements(&current_element);
202        }
203#ifdef DEBUG_SERVICE_CONF
204        fprintf(stderr,"CURRENT_ELEMENT\n");
205        dumpElements(current_element);
206        fprintf(stderr,"SERVICE INPUTS\n");
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
216        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
217        fflush(stderr);
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;
226        current_element->child=NULL;
227        current_element->next=NULL;
228      }
229      wait_outputs=1;
230      current_data=2;
231      previous_data=2;
232    }
233    else
234      if(strncasecmp($2,"MetaData",8)==0){
235        previous_data=current_data;
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");
240          fprintf(stderr,"LINE %d",__LINE__);
241#endif
242          addMapToMap(&current_element->content,current_content);
243          freeMap(&current_content);
244          free(current_content);
245          if(previous_data==1 || previous_data==2)
246            wait_metadata=true;
247          else
248            wait_mainmetadata=true;
249        }
250        else{
251          if(previous_data==1 || previous_data==2)
252            wait_metadata=true;
253          else
254            wait_mainmetadata=true;
255        }
256        current_content=NULL;
257      }
258      else
259        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
260           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
261           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
262          current_data=4;
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;
271          current_content=NULL;
272        }
273        else
274          if(strncasecmp($2,"Default",7)==0){
275            wait_defaults=true;
276            current_data=5;
277          }
278          else
279            if(strncasecmp($2,"Supported",9)==0){
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);
288  fflush(stdout);
289#endif
290}
291 ;
292
293// Attributeetoile
294// regle 41
295// une liste qui peut etre vide d'attributs
296// utiliser la récursivité a gauche
297Attributeetoile
298: Attributeetoile attribute  {}
299 |                                {/* Epsilon */}
300 ;
301
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 ;
316
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
324 : INFCAR ID Attributeetoile SLASH SUPCAR       {
325#ifdef DEBUG_SERVICE_CONF
326  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
327#endif
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 }
345 ;
346
347// ETag
348// BALISE FERMANTE
349// les separateurs après ID sont filtrés
350ETag
351 : INFCAR SLASH ID SUPCAR
352{
353#ifdef DEBUG_SERVICE_CONF
354  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
355#endif
356  if(strcmp($3,"DataInputs")==0){
357    current_data=1;
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    }
381  }
382  if(strcmp($3,"DataOutputs")==0){
383    current_data=2;
384  }
385  if(strcmp($3,"MetaData")==0){
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    }
407    current_data=previous_data;
408    wait_mainmetadata=false;
409    wait_metadata=false;
410  }
411  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
412     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
413    if(current_element->format==NULL)
414      current_element->format=zStrdup($3);
415    current_content=NULL;
416  }
417  if(strcmp($3,"Default")==0){
418    current_data=previous_data;
419    if(current_element->defaults==NULL){
420      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
421      current_element->defaults->content=NULL;
422    }
423    addMapToMap(&current_element->defaults->content,current_content);
424    freeMap(&current_content);
425    free(current_content);
426    current_element->defaults->next=NULL;
427    wait_defaults=false;
428    current_content=NULL;
429    current_element->supported=NULL;
430    current_element->next=NULL;
431  }
432  if(strcmp($3,"Supported")==0){
433    current_data=previous_data;
434    if(current_element->supported==NULL){
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      }
447    }
448    else{
449#ifdef DEBUG_SERVICE_CONF
450      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
451#endif
452      addMapToIoType(&current_element->supported,current_content);
453      freeMap(&current_content);
454      free(current_content);
455      current_content=NULL;
456#ifdef DEBUG_SERVICE_CONF
457      dumpElements(current_element);
458      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
459#endif
460    }
461    current_content=NULL;
462  }
463}
464 ;
465
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 ;
493
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
506pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
507| EPAIR {
508#ifdef DEBUG_SERVICE_CONF
509  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
510  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
511  dumpMap(current_content);
512  fflush(stderr);
513#endif
514  if($1!=NULL && curr_key!=NULL){
515    if(current_content==NULL){
516#ifdef DEBUG_SERVICE_CONF
517      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
518#endif
519      current_content=createMap(curr_key,$1);
520#ifdef DEBUG_SERVICE_CONF
521      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
522#endif
523    }
524    else{
525#ifdef DEBUG_SERVICE_CONF
526      dumpMap(current_content);
527      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
528#endif
529      addToMap(current_content,curr_key,$1);
530#ifdef DEBUG_SERVICE_CONF
531      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
532#endif   
533    }
534  }
535#ifdef DEBUG_SERVICE_CONF
536  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
537  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
538  dumpMap(current_content);
539  fflush(stderr);
540#endif
541  if(curr_key!=NULL){
542    free(curr_key);
543    curr_key=NULL;
544  }
545  }
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"); }
547 ;
548
549
550processid
551: ANID  {
552#ifdef DEBUG_SERVICE_CONF
553  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
554#endif
555  if(data==-1){
556    data=1;
557    if($1!=NULL){
558      char *cen=zStrdup($1);
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    }
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);
575          my_service->inputs->next=NULL;
576          tmp_count++;
577        }
578        else{
579          addToElements(&my_service->inputs,current_element);
580        }
581#ifdef DEBUG_SERVICE_CONF
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__);
585        dumpElements(my_service->inputs);
586#endif
587        freeElements(&current_element);
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
611        if($1!=NULL){
612          char *cen=zStrdup($1);
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);
619#ifdef DEBUG_SERVICE_CONF
620          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
621#endif
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;
628#ifdef DEBUG_SERVICE_CONF
629          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
630#endif
631        }
632      }
633    }
634    else
635      if(current_data==2){
636        wait_outputs=1;
637        if(wait_inputs){
638          if(current_element!=NULL && current_element->name!=NULL){
639            if(my_service->outputs==NULL){
640              my_service->outputs=dupElements(current_element);
641              my_service->outputs->next=NULL;
642            }
643            else{
644#ifdef DEBUG_SERVICE_CONF
645              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
646#endif
647              addToElements(&my_service->outputs,current_element);
648            }
649#ifdef DEBUG_SERVICE_CONF
650            dumpElements(current_element);
651            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
652#endif
653            freeElements(&current_element);
654            free(current_element);
655            current_element=NULL;
656#ifdef DEBUG_SERVICE_CONF
657            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
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);
671            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
672#endif
673            if($1!=NULL){
674              char *cen=zStrdup($1);
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            }
688          }
689
690          current_content=NULL;
691        }
692        else
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);
698#ifdef DEBUG_SERVICE_CONF
699            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
700            dupElements(current_element);
701#endif
702            freeElements(&current_element);
703            free(current_element);
704            current_element=NULL;
705            current_element=(elements*)malloc(ELEMENTS_SIZE);
706            char *cen=zStrdup($1);
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;
719          }
720          else{
721#ifdef DEBUG_SERVICE_CONF
722            fprintf(stderr,"NAME OUT %s\n",$1);
723            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
724#endif
725            if($1!=NULL){
726              char *cen=zStrdup($1);
727              current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
728              cen[strlen(cen)-1]=0;
729#ifdef DEBUG
730              fprintf(stderr,"tmp %s\n",cen);
731#endif
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            }
743          }
744        wait_inputs=false;
745        wait_outputs=1;
746        //wait_outputs=true;
747      }
748  }
749 }
750 ;
751
752%%
753
754/**
755 * Print on stderr the message and the line number of the error which occured.
756 *
757 * @param s the error message
758 */
759void srerror(const char *s)
760{
761  if(debug)
762    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
763}
764
765/**
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
772 */
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  }
779#ifdef DEBUG_SERVICE_CONF
780  fprintf(stderr,"(STARTING)FREE current_element\n");
781#endif
782  if(current_element!=NULL){
783    freeElements(&current_element);
784    free(current_element);
785    current_element=NULL;
786  }
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;
795  wait_outputs=-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){
805    setMapInMaps(conf,"lenv","message","file not found");
806    return -1;
807  }
808
809  int resultatYYParse = srparse() ;
810
811#ifdef DEBUG_SERVICE_CONF
812  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
813  dumpElements(current_element);
814#endif
815  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
816    if(current_content!=NULL){
817      addMapToMap(&current_element->content,current_content);
818    }
819    if(my_service->outputs==NULL){ 
820#ifdef DEBUG_SERVICE_CONF
821      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
822#endif
823      my_service->outputs=dupElements(current_element);
824      my_service->outputs->next=NULL;
825    }
826    else{
827#ifdef DEBUG_SERVICE_CONF
828      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
829#endif
830      addToElements(&my_service->outputs,current_element);
831    }
832#ifdef DEBUG_SERVICE_CONF
833    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
834#endif
835    freeElements(&current_element);
836    free(current_element);
837    current_element=NULL;
838#ifdef DEBUG_SERVICE_CONF
839    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
840#endif
841  }
842  if(current_element!=NULL){
843    freeElements(&current_element);
844    free(current_element);
845    current_element=NULL;
846  }
847  int contentOnly=false;
848  if(current_content!=NULL){
849    if(my_service->content==NULL){
850      addMapToMap(&my_service->content,current_content);
851      contentOnly=true;
852      wait_maincontent=false;
853    }
854    freeMap(&current_content);
855    free(current_content);
856    current_content=NULL;
857  }
858  fclose(srin);
859#ifdef DEBUG_SERVICE_CONF
860  dumpService(my_service);
861#endif
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))){
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;
871
872#ifndef WIN32
873  srlex_destroy();
874#endif
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