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

Last change on this file since 633 was 621, checked in by djay, 9 years ago

Major update. Creation of a basic parsing api. Call validateRequest after fork if any.

File size: 24.0 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->next=NULL;
177    }
178    wait_inputs=true;
179    current_data=1;
180    previous_data=1;
181  }
182  else
183    if(strncasecmp($2,"DataOutputs",11)==0){
184      if(wait_inputs==true){
185#ifdef DEBUG_SERVICE_CONF
186        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
187        fprintf(stderr,"CURRENT_ELEMENT\n");
188        dumpElements(current_element);
189        fprintf(stderr,"SERVICE INPUTS\n");
190        dumpElements(my_service->inputs);
191        dumpService(my_service);
192#endif 
193        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
194          my_service->inputs=dupElements(current_element);
195          my_service->inputs->next=NULL;
196          freeElements(&current_element);
197        }
198        else if(current_element!=NULL && current_element->name!=NULL){
199          addToElements(&my_service->inputs,current_element);
200          freeElements(&current_element);
201        }
202#ifdef DEBUG_SERVICE_CONF
203        fprintf(stderr,"CURRENT_ELEMENT\n");
204        dumpElements(current_element);
205        fprintf(stderr,"SERVICE INPUTS\n");
206        dumpElements(my_service->inputs);
207        fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
208#endif
209        free(current_element);
210        current_element=NULL;
211        wait_inputs=false;
212      }
213      if(current_element==NULL){
214#ifdef DEBUG_SERVICE_CONF
215        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
216        fflush(stderr);
217#endif
218        current_element=(elements*)malloc(ELEMENTS_SIZE);
219        current_element->name=NULL;
220        current_element->content=NULL;
221        current_element->metadata=NULL;
222        current_element->format=NULL;
223        current_element->defaults=NULL;
224        current_element->supported=NULL;
225        current_element->next=NULL;
226      }
227      wait_outputs=1;
228      current_data=2;
229      previous_data=2;
230    }
231    else
232      if(strncasecmp($2,"MetaData",8)==0){
233        previous_data=current_data;
234        current_data=3;
235        if(current_element!=NULL){
236#ifdef DEBUG_SERVICE_CONF
237          fprintf(stderr,"add current_content to current_element->content\n");
238          fprintf(stderr,"LINE %d",__LINE__);
239#endif
240          addMapToMap(&current_element->content,current_content);
241          freeMap(&current_content);
242          free(current_content);
243          if(previous_data==1 || previous_data==2)
244            wait_metadata=true;
245          else
246            wait_mainmetadata=true;
247        }
248        else{
249          if(previous_data==1 || previous_data==2)
250            wait_metadata=true;
251          else
252            wait_mainmetadata=true;
253        }
254        current_content=NULL;
255      }
256      else
257        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
258           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
259           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
260          current_data=4;
261          addMapToMap(&current_element->content,current_content);
262          freeMap(&current_content);
263          free(current_content);
264          current_element->next=NULL;
265          if($2!=NULL)
266            current_element->format=zStrdup($2);
267          current_element->defaults=NULL;
268          current_element->supported=NULL;
269          current_content=NULL;
270        }
271        else
272          if(strncasecmp($2,"Default",7)==0){
273            wait_defaults=true;
274            current_data=5;
275          }
276          else
277            if(strncasecmp($2,"Supported",9)==0){
278              wait_supporteds=true;
279              if(wait_defaults==true){
280                defaultsc++;
281              }
282              current_data=5;
283            }
284#ifdef DEBUG_SERVICE_CONF
285  printf("* Identifiant : %s\n",$2);
286  fflush(stdout);
287#endif
288}
289 ;
290
291// Attributeetoile
292// regle 41
293// une liste qui peut etre vide d'attributs
294// utiliser la récursivité a gauche
295Attributeetoile
296: Attributeetoile attribute  {}
297 |                                {/* Epsilon */}
298 ;
299
300// attribute
301// regle 41
302// un attribut est compose d'un identifiant
303// d'un "="
304// et d'une définition de chaine de caractere
305// ( "xxx" ou 'xxx' )
306attribute
307 : ID Eq ATTVALUE               
308{
309#ifdef DEBUG_SERVICE_CONF
310  printf ("attribute : %s\n",$1) ;
311#endif
312}
313 ;
314
315// EmptyElemTag
316// regle 44
317// ICI ON DEFINIT NEUTRE
318// on ne renvoie pas de char*
319// parce qu'il n'y a pas de comparaisons a faire
320// avec un identifiant d'une balise jumelle
321EmptyElemTag
322 : INFCAR ID Attributeetoile SLASH SUPCAR       {
323#ifdef DEBUG_SERVICE_CONF
324  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
325#endif
326   if(strncasecmp($2,"Default",7)==0){
327     wait_defaults=false;
328     current_data=previous_data;
329     if(current_element->defaults==NULL){
330       current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
331       current_element->defaults->content=NULL;
332     }
333     addMapToMap(&current_element->defaults->content,current_content);
334     freeMap(&current_content);
335     free(current_content);
336     current_element->defaults->next=NULL;
337     wait_defaults=false;
338     current_content=NULL;
339     current_element->supported=NULL;
340     current_element->next=NULL;
341   }
342 }
343 ;
344
345// ETag
346// BALISE FERMANTE
347// les separateurs après ID sont filtrés
348ETag
349 : INFCAR SLASH ID SUPCAR
350{
351#ifdef DEBUG_SERVICE_CONF
352  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
353#endif
354  if(strcmp($3,"DataInputs")==0){
355    current_data=1;
356    if(current_content!=NULL){
357      if(current_element->content==NULL){
358        addMapToMap(&current_element->content,current_content);
359      }
360      freeMap(&current_content);
361      free(current_content);
362      current_content=NULL;
363    }
364    if(current_element!=NULL){
365      if(my_service->content!=NULL && current_element->name!=NULL){
366        if(my_service->inputs==NULL){
367          my_service->inputs=dupElements(current_element);
368          my_service->inputs->next=NULL;
369          tmp_count++;
370        }
371        else{
372          addToElements(&my_service->inputs,current_element);
373        }
374        freeElements(&current_element);
375        free(current_element);
376        current_element=NULL;
377      }
378    }
379  }
380  if(strcmp($3,"DataOutputs")==0){
381    current_data=2;
382  }
383  if(strcmp($3,"MetaData")==0){
384    if(current_content!=NULL){
385#ifdef DEBUG_SERVICE_CONF
386      fprintf(stderr,"add current_content to current_element->content\n");
387      fprintf(stderr,"LINE %d",__LINE__);
388#endif
389      if(wait_metadata){
390        current_element->metadata=NULL;
391        addMapToMap(&current_element->metadata,current_content);
392        current_element->next=NULL;
393        current_element->defaults=NULL;
394        current_element->supported=NULL;
395      }else{
396        if(wait_mainmetadata){
397          addMapToMap(&my_service->metadata,current_content);
398        }
399      }
400
401      freeMap(&current_content);
402      free(current_content);
403      current_content=NULL;
404    }
405    current_data=previous_data;
406    wait_mainmetadata=false;
407    wait_metadata=false;
408  }
409  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
410     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
411    if(current_element->format==NULL)
412      current_element->format=zStrdup($3);
413    current_content=NULL;
414  }
415  if(strcmp($3,"Default")==0){
416    current_data=previous_data;
417    if(current_element->defaults==NULL){
418      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
419      current_element->defaults->content=NULL;
420    }
421    addMapToMap(&current_element->defaults->content,current_content);
422    freeMap(&current_content);
423    free(current_content);
424    current_element->defaults->next=NULL;
425    wait_defaults=false;
426    current_content=NULL;
427    current_element->supported=NULL;
428    current_element->next=NULL;
429  }
430  if(strcmp($3,"Supported")==0){
431    current_data=previous_data;
432    if(current_element->supported==NULL){
433      if(current_content!=NULL){
434        current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
435        current_element->supported->content=NULL;
436        addMapToMap(&current_element->supported->content,current_content);
437        freeMap(&current_content);
438        free(current_content);
439        current_element->supported->next=NULL;
440        current_content=NULL;
441      }else{
442        current_element->supported=NULL;
443        current_element->next=NULL;
444      }
445    }
446    else{
447#ifdef DEBUG_SERVICE_CONF
448      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
449#endif
450      addMapToIoType(&current_element->supported,current_content);
451      freeMap(&current_content);
452      free(current_content);
453      current_content=NULL;
454#ifdef DEBUG_SERVICE_CONF
455      dumpElements(current_element);
456      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
457#endif
458    }
459    current_content=NULL;
460  }
461}
462 ;
463
464//======================================================
465// contentetoile
466//======================================================
467// regle 43
468// ENTRE 2 BALISES
469// entre 2 balises, on peut avoir :
470// --- OUVRANTE CONTENU FERMANTE (recursivement !)
471// --- DU TEXTE quelconque
472// --- COMMENTS
473// --- DES PROCESSES INSTRUCTIONS
474// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
475// --- EPSILON
476// ### et/ou tout ca a la suite en nombre indeterminé
477// ### donc c'est un operateur etoile (*)
478//======================================================
479contentetoile
480: contentetoile element           {}
481 | contentetoile PIERROR                  {srerror("processing instruction <?xml ?> impossible\n");}
482 | contentetoile PI                       {}
483///// on filtre les commentaires | contentetoile comment              {}
484 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
485 | contentetoile pair {}
486 | contentetoile processid {}
487 | contentetoile texteinterbalise         {}
488 | contentetoile CDATA {} 
489 | {/* Epsilon */}
490 ;
491
492// texteinterbalise
493// regle 14
494// DU TEXTE quelconque
495// c'est du CHARDATA
496// il y a eut un probleme avec ID,
497// on a mis des starts conditions,
498// maintenant on croise les ID dans les dbalises
499// et des CHARDATA hors des balises
500texteinterbalise
501 : CHARDATA             {}
502 ;
503
504pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
505| EPAIR {
506#ifdef DEBUG_SERVICE_CONF
507  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
508  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
509  dumpMap(current_content);
510  fflush(stderr);
511#endif
512  if($1!=NULL && curr_key!=NULL){
513    if(current_content==NULL){
514#ifdef DEBUG_SERVICE_CONF
515      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
516#endif
517      current_content=createMap(curr_key,$1);
518#ifdef DEBUG_SERVICE_CONF
519      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
520#endif
521    }
522    else{
523#ifdef DEBUG_SERVICE_CONF
524      dumpMap(current_content);
525      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
526#endif
527      addToMap(current_content,curr_key,$1);
528#ifdef DEBUG_SERVICE_CONF
529      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
530#endif   
531    }
532  }
533#ifdef DEBUG_SERVICE_CONF
534  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
535  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
536  dumpMap(current_content);
537  fflush(stderr);
538#endif
539  if(curr_key!=NULL){
540    free(curr_key);
541    curr_key=NULL;
542  }
543  }
544| 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"); }
545 ;
546
547
548processid
549: ANID  {
550#ifdef DEBUG_SERVICE_CONF
551  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
552#endif
553  if(data==-1){
554    data=1;
555    if($1!=NULL){
556      char *cen=zStrdup($1);
557      my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
558      cen[strlen(cen)-1]=0;
559      cen+=1;
560      sprintf(my_service->name,"%s",cen);
561      cen-=1;
562      free(cen);
563      my_service->content=NULL;
564      my_service->metadata=NULL;
565      my_service->inputs=NULL;
566      my_service->outputs=NULL;
567    }
568  } else {
569    if(current_data==1){
570      if(my_service->content!=NULL && current_element->name!=NULL){
571        if(my_service->inputs==NULL){
572          my_service->inputs=dupElements(current_element);
573          my_service->inputs->next=NULL;
574          tmp_count++;
575        }
576        else{
577          addToElements(&my_service->inputs,current_element);
578        }
579#ifdef DEBUG_SERVICE_CONF
580        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
581        dumpElements(current_element);
582        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
583        dumpElements(my_service->inputs);
584#endif
585        freeElements(&current_element);
586        free(current_element);
587        current_element=NULL;
588#ifdef DEBUG_SERVICE_CONF
589        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
590#endif
591        current_element=(elements*)malloc(ELEMENTS_SIZE);
592        current_element->name=NULL;
593        current_element->content=NULL;
594        current_element->metadata=NULL;
595        current_element->format=NULL;
596        current_element->defaults=NULL;
597        current_element->supported=NULL;
598        current_element->next=NULL;
599      }
600      if(current_element->name==NULL){
601#ifdef DEBUG_SERVICE_CONF
602        fprintf(stderr,"NAME IN %s (current - %s)\n",
603                $1,current_element->name);
604#endif
605        wait_inputs=true;
606#ifdef DEBUG_SERVICE_CONF
607        fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
608#endif
609        if($1!=NULL){
610          char *cen=zStrdup($1);
611          current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
612          cen[strlen(cen)-1]=0;
613          cen+=1;
614          sprintf(current_element->name,"%s",cen);
615          cen-=1;
616          free(cen);
617#ifdef DEBUG_SERVICE_CONF
618          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
619#endif
620          current_element->content=NULL;
621          current_element->metadata=NULL;
622          current_element->format=NULL;
623          current_element->defaults=NULL;
624          current_element->supported=NULL;
625          current_element->next=NULL;
626#ifdef DEBUG_SERVICE_CONF
627          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
628#endif
629        }
630      }
631    }
632    else
633      if(current_data==2){
634        wait_outputs=1;
635        if(wait_inputs){
636          if(current_element!=NULL && current_element->name!=NULL){
637            if(my_service->outputs==NULL){
638              my_service->outputs=dupElements(current_element);
639              my_service->outputs->next=NULL;
640            }
641            else{
642#ifdef DEBUG_SERVICE_CONF
643              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
644#endif
645              addToElements(&my_service->outputs,current_element);
646            }
647#ifdef DEBUG_SERVICE_CONF
648            dumpElements(current_element);
649            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
650#endif
651            freeElements(&current_element);
652            free(current_element);
653            current_element=NULL;
654#ifdef DEBUG_SERVICE_CONF
655            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
656#endif
657            current_element=(elements*)malloc(ELEMENTS_SIZE);
658            current_element->name=NULL;
659            current_element->content=NULL;
660            current_element->metadata=NULL;
661            current_element->format=NULL;
662            current_element->defaults=NULL;
663            current_element->supported=NULL;
664            current_element->next=NULL;
665          }
666          if(current_element->name==NULL){
667#ifdef DEBUG_SERVICE_CONF
668            fprintf(stderr,"NAME OUT %s\n",$1);
669            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
670#endif
671            if($1!=NULL){
672              char *cen=zStrdup($1);
673              current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
674              cen[strlen(cen)-1]=0;
675              cen+=1;
676              sprintf(current_element->name,"%s",cen);
677              cen-=1;
678              free(cen);
679              current_element->content=NULL;
680              current_element->metadata=NULL;
681              current_element->format=NULL;
682              current_element->defaults=NULL;
683              current_element->supported=NULL;
684              current_element->next=NULL;
685            }
686          }
687
688          current_content=NULL;
689        }
690        else
691          if(current_element!=NULL && current_element->name!=NULL){
692            if(my_service->outputs==NULL)
693              my_service->outputs=dupElements(current_element);
694            else
695              addToElements(&my_service->outputs,current_element);
696#ifdef DEBUG_SERVICE_CONF
697            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
698            dupElements(current_element);
699#endif
700            freeElements(&current_element);
701            free(current_element);
702            current_element=NULL;
703            current_element=(elements*)malloc(ELEMENTS_SIZE);
704            char *cen=zStrdup($1);
705            current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
706            cen[strlen(cen)-1]=0;
707            cen+=1;
708            sprintf(current_element->name,"%s",cen);
709            cen-=1;
710            free(cen);
711            current_element->content=NULL;
712            current_element->metadata=NULL;
713            current_element->format=NULL;
714            current_element->defaults=NULL;
715            current_element->supported=NULL;
716            current_element->next=NULL;
717          }
718          else{
719#ifdef DEBUG_SERVICE_CONF
720            fprintf(stderr,"NAME OUT %s\n",$1);
721            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
722#endif
723            if($1!=NULL){
724              char *cen=zStrdup($1);
725              current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
726              cen[strlen(cen)-1]=0;
727#ifdef DEBUG
728              fprintf(stderr,"tmp %s\n",cen);
729#endif
730              cen+=1;
731              sprintf(current_element->name,"%s",cen);
732              cen-=1;
733              free(cen);
734              current_element->content=NULL;
735              current_element->metadata=NULL;
736              current_element->format=NULL;
737              current_element->defaults=NULL;
738              current_element->supported=NULL;
739              current_element->next=NULL;
740            }
741          }
742        wait_inputs=false;
743        wait_outputs=1;
744        //wait_outputs=true;
745      }
746  }
747 }
748 ;
749
750%%
751
752/**
753 * Print on stderr the message and the line number of the error which occured.
754 *
755 * @param s the error message
756 */
757void srerror(const char *s)
758{
759  if(debug)
760    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
761}
762
763/**
764 * Parse a ZCFG file and fill the service structure.
765 *
766 * @param conf the conf maps containing the main.cfg settings
767 * @param file the fullpath to the ZCFG file
768 * @param service the service structure to fill
769 * @return 0 on success, -1 on failure
770 */
771int getServiceFromFile(maps* conf,const char* file,service** service){
772  if(current_content!=NULL){
773    freeMap(&current_content);
774    free(current_content);
775    current_content=NULL;
776  }
777#ifdef DEBUG_SERVICE_CONF
778  fprintf(stderr,"(STARTING)FREE current_element\n");
779#endif
780  if(current_element!=NULL){
781    freeElements(&current_element);
782    free(current_element);
783    current_element=NULL;
784  }
785  my_service=NULL;
786
787  wait_maincontent=true;
788  wait_mainmetadata=false;
789  wait_metadata=false;
790  wait_inputs=false;
791  wait_defaults=false;
792  wait_supporteds=false;
793  wait_outputs=-1;
794  wait_data=false;
795  data=-1;
796  previous_data=1;
797  current_data=0;
798 
799  my_service=*service;
800
801  srin = fopen(file,"r");
802  if (srin==NULL){
803    setMapInMaps(conf,"lenv","message","file not found");
804    return -1;
805  }
806
807  int resultatYYParse = srparse() ;
808
809#ifdef DEBUG_SERVICE_CONF
810  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
811  dumpElements(current_element);
812#endif
813  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
814    if(my_service->outputs==NULL){ 
815#ifdef DEBUG_SERVICE_CONF
816      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
817#endif
818      my_service->outputs=dupElements(current_element);
819      my_service->outputs->next=NULL;
820    }
821    else{
822#ifdef DEBUG_SERVICE_CONF
823      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
824#endif
825      addToElements(&my_service->outputs,current_element);
826    }
827#ifdef DEBUG_SERVICE_CONF
828    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
829#endif
830    freeElements(&current_element);
831    free(current_element);
832    current_element=NULL;
833#ifdef DEBUG_SERVICE_CONF
834    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
835#endif
836  }
837  if(current_element!=NULL){
838    freeElements(&current_element);
839    free(current_element);
840    current_element=NULL;
841  }
842  int contentOnly=false;
843  if(current_content!=NULL){
844    if(my_service->content==NULL){
845      addMapToMap(&my_service->content,current_content);
846      contentOnly=true;
847      wait_maincontent=false;
848    }
849    freeMap(&current_content);
850    free(current_content);
851    current_content=NULL;
852  }
853  fclose(srin);
854#ifdef DEBUG_SERVICE_CONF
855  dumpService(my_service);
856#endif
857  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))){
858    setMapInMaps(conf,"lenv","message",srlval.chaine);
859#ifndef WIN32
860    srlex_destroy();
861#endif
862    return -1;
863  }
864  else
865    *service=my_service;
866
867#ifndef WIN32
868  srlex_destroy();
869#endif
870  return resultatYYParse;
871}
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