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

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

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

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

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

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png