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

Last change on this file since 621 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
RevLine 
[607]1/*
[1]2 * Author : Gérald FENOY
3 *
[621]4 * Copyright (c) 209-2015 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
[1]23 */
[607]24%{
[1]25
26#include <string>
27#include <stdio.h>
28#include <ctype.h>
29#include <service.h>
30
31static int tmp_count=1;
32static int defaultsc=0;
33static bool wait_maincontent=true;
34static bool wait_mainmetadata=false;
35static bool wait_metadata=false;
36static bool wait_inputs=false;
37static bool wait_defaults=false;
38static bool wait_supporteds=false;
[618]39static bool wait_outputs=false;
[1]40static bool wait_data=false;
41static service* my_service=NULL;
42static map* current_content=NULL;
43static elements* current_element=NULL;
44static char* curr_key;
45static int debug=0;
46static int data=-1;
47static int previous_data=0;
48static int current_data=0;
49// namespace
50using namespace std;
51
52// srerror
[114]53void srerror(const char *s);
[1]54
55// usage ()
56void usage(void) ;
57
58// srdebug
59extern int srdebug;
60
61extern char srtext[];
62
63// srlineno
64extern int srlineno;
65
66// srin
67extern FILE* srin;
68
69// srlex
70extern int srlex(void);
[9]71extern int srlex_destroy(void);
[1]72
73%}
74
75
76
77%union
78{char * s;char* chaine;char* key;char* val;}
79
80// jetons //
81%token <s> ID
82%token <s> CHAINE
[607]83
[1]84%token INFCAR SUPCAR
[607]85
[1]86/* / = a1  texte "texte" */
87%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID
88%type <chaine> PAIR
89%type <chaine> EPAIR
90%type <chaine> SPAIR
[607]91
[1]92/* <!-- xxx -> <? xxx yyy ?> */
93%token PI PIERROR /** COMMENT **/
[607]94
[1]95/* <!-- xxx -> <? xxx yyy ?> */
96%token ERREURGENERALE CDATA WHITESPACE NEWLINE
97%type <s> STag
98%type <s> ETag
99%type <s> ANID
100
[607]101// % start
102
[1]103%%
[607]104// document
[1]105// regle 1
106// on est a la racine du fichier xml
107document
108 : miscetoile element miscetoile {}
109 | contentetoile processid contentetoile document {}
110 ;
111
112miscetoile
113 : miscetoile PIERROR {  srerror("processing instruction begining with <?xml ?> impossible\n");}
114 | miscetoile PI {}
115 | {}
116 ;
117// element
118// regle 39
119// OUVRANTE CONTENU FERMANTE obligatoirement
120// ou neutre
121// on ne peut pas avoir Epsilon
122// un fichier xml ne peut pas etre vide ou seulement avec un prolog
123element
124 : STag contentetoile ETag     
125{
126}
[20]127
[1]128// pour neutre
129// on a rien a faire, meme pas renvoyer l identificateur de balise
130// vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
131 | EmptyElemTag          {}
132 ;
[20]133
[1]134// STag
135// regle 40
136// BALISE OUVRANTE
137// on est obligé de faire appel a infcar et supcar
138// pour acceder aux start conditions DANSBALISE et INITIAL
139STag
140: INFCAR ID Attributeetoile SUPCAR
141{
[379]142#ifdef DEBUG_SERVICE_CONF
[621]143  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
[379]144  fflush(stderr);
[607]145  dumpMap(current_content);
[379]146#endif
[1]147  if(my_service->content==NULL){
148#ifdef DEBUG_SERVICE_CONF
149    fprintf(stderr,"NO CONTENT\n");
150#endif
[9]151    addMapToMap(&my_service->content,current_content);
152    freeMap(&current_content);
153    free(current_content);
[1]154    current_content=NULL;
155    my_service->metadata=NULL;
156    wait_maincontent=false;
157  }
[9]158  if(strncasecmp($2,"DataInputs",10)==0){
[1]159    if(current_element==NULL){
160#ifdef DEBUG_SERVICE_CONF
[104]161      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
[1]162#endif
163      freeElements(&current_element);
164      free(current_element);
165#ifdef DEBUG_SERVICE_CONF
[104]166      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
[1]167#endif
168      current_element=NULL;
169      current_element=(elements*)malloc(ELEMENTS_SIZE);
170      current_element->name=NULL;
171      current_element->content=NULL;
172      current_element->metadata=NULL;
173      current_element->format=NULL;
174      current_element->defaults=NULL;
175      current_element->supported=NULL;
176      current_element->next=NULL;
177    }
178    wait_inputs=true;
179    current_data=1;
180    previous_data=1;
181  }
182  else
[9]183    if(strncasecmp($2,"DataOutputs",11)==0){
[1]184      if(wait_inputs==true){
185#ifdef DEBUG_SERVICE_CONF
[104]186        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
[9]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);
[65]192#endif 
[469]193        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
[1]194          my_service->inputs=dupElements(current_element);
[9]195          my_service->inputs->next=NULL;
[469]196          freeElements(&current_element);
[9]197        }
[57]198        else if(current_element!=NULL && current_element->name!=NULL){
[9]199          addToElements(&my_service->inputs,current_element);
[469]200          freeElements(&current_element);
[57]201        }
[1]202#ifdef DEBUG_SERVICE_CONF
[9]203        fprintf(stderr,"CURRENT_ELEMENT\n");
[1]204        dumpElements(current_element);
[9]205        fprintf(stderr,"SERVICE INPUTS\n");
[1]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
[104]215        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
[379]216        fflush(stderr);
[1]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      }
[607]227      wait_outputs=1;
[1]228      current_data=2;
[65]229      previous_data=2;
[1]230    }
231    else
[9]232      if(strncasecmp($2,"MetaData",8)==0){
[73]233        previous_data=current_data;
[1]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");
[104]238          fprintf(stderr,"LINE %d",__LINE__);
[1]239#endif
240          addMapToMap(&current_element->content,current_content);
241          freeMap(&current_content);
242          free(current_content);
[104]243          if(previous_data==1 || previous_data==2)
244            wait_metadata=true;
245          else
246            wait_mainmetadata=true;
[1]247        }
248        else{
[104]249          if(previous_data==1 || previous_data==2)
250            wait_metadata=true;
251          else
252            wait_mainmetadata=true;
[1]253        }
254        current_content=NULL;
255      }
256      else
[9]257        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
[76]258           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
259           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
[1]260          current_data=4;
[621]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;
[1]269          current_content=NULL;
270        }
271        else
[9]272          if(strncasecmp($2,"Default",7)==0){
[1]273            wait_defaults=true;
274            current_data=5;
275          }
276          else
[9]277            if(strncasecmp($2,"Supported",9)==0){
[1]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);
[379]286  fflush(stdout);
[1]287#endif
288}
289 ;
[20]290
[1]291// Attributeetoile
292// regle 41
293// une liste qui peut etre vide d'attributs
294// utiliser la récursivité a gauche
295Attributeetoile
[621]296: Attributeetoile attribute  {}
[1]297 |                                {/* Epsilon */}
298 ;
[20]299
[1]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 ;
[20]314
[1]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
[226]322 : INFCAR ID Attributeetoile SLASH SUPCAR       {
[379]323#ifdef DEBUG_SERVICE_CONF
324  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
325#endif
[226]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 }
[1]343 ;
[20]344
[1]345// ETag
346// BALISE FERMANTE
347// les separateurs après ID sont filtrés
348ETag
349 : INFCAR SLASH ID SUPCAR
350{
[379]351#ifdef DEBUG_SERVICE_CONF
[621]352  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
[379]353#endif
[1]354  if(strcmp($3,"DataInputs")==0){
355    current_data=1;
[607]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    }
[1]379  }
380  if(strcmp($3,"DataOutputs")==0){
381    current_data=2;
382  }
383  if(strcmp($3,"MetaData")==0){
[621]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    }
[1]405    current_data=previous_data;
[621]406    wait_mainmetadata=false;
407    wait_metadata=false;
[1]408  }
409  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
410     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
[621]411    if(current_element->format==NULL)
412      current_element->format=zStrdup($3);
[1]413    current_content=NULL;
414  }
415  if(strcmp($3,"Default")==0){
416    current_data=previous_data;
417    if(current_element->defaults==NULL){
[9]418      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
419      current_element->defaults->content=NULL;
[1]420    }
[9]421    addMapToMap(&current_element->defaults->content,current_content);
422    freeMap(&current_content);
423    free(current_content);
[1]424    current_element->defaults->next=NULL;
425    wait_defaults=false;
426    current_content=NULL;
427    current_element->supported=NULL;
[57]428    current_element->next=NULL;
[1]429  }
430  if(strcmp($3,"Supported")==0){
431    current_data=previous_data;
432    if(current_element->supported==NULL){
[57]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      }
[1]445    }
[9]446    else{
[57]447#ifdef DEBUG_SERVICE_CONF
[9]448      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
[1]449#endif
[57]450      addMapToIoType(&current_element->supported,current_content);
[9]451      freeMap(&current_content);
452      free(current_content);
453      current_content=NULL;
[57]454#ifdef DEBUG_SERVICE_CONF
455      dumpElements(current_element);
[9]456      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
457#endif
[1]458    }
459    current_content=NULL;
460  }
461}
462 ;
[20]463
[1]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 ;
[20]491
[1]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
[104]504pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
[1]505| EPAIR {
506#ifdef DEBUG_SERVICE_CONF
[621]507  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
[104]508  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
509  dumpMap(current_content);
510  fflush(stderr);
[1]511#endif
[539]512  if($1!=NULL && curr_key!=NULL){
[104]513    if(current_content==NULL){
[1]514#ifdef DEBUG_SERVICE_CONF
[104]515      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]516#endif
[104]517      current_content=createMap(curr_key,$1);
[1]518#ifdef DEBUG_SERVICE_CONF
[104]519      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]520#endif
[104]521    }
522    else{
[1]523#ifdef DEBUG_SERVICE_CONF
[104]524      dumpMap(current_content);
525      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
[1]526#endif
[104]527      addToMap(current_content,curr_key,$1);
[1]528#ifdef DEBUG_SERVICE_CONF
[104]529      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
[1]530#endif   
[104]531    }
[1]532  }
533#ifdef DEBUG_SERVICE_CONF
534  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
[93]535  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[379]536  dumpMap(current_content);
[1]537  fflush(stderr);
538#endif
[9]539  if(curr_key!=NULL){
540    free(curr_key);
541    curr_key=NULL;
[1]542  }
[9]543  }
[453]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"); }
[1]545 ;
546
547
548processid
549: ANID  {
[379]550#ifdef DEBUG_SERVICE_CONF
[621]551  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
[379]552#endif
[1]553  if(data==-1){
554    data=1;
[104]555    if($1!=NULL){
[453]556      char *cen=zStrdup($1);
[104]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    }
[1]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);
[9]573          my_service->inputs->next=NULL;
[1]574          tmp_count++;
575        }
576        else{
[9]577          addToElements(&my_service->inputs,current_element);
[1]578        }
579#ifdef DEBUG_SERVICE_CONF
[9]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__);
[1]583        dumpElements(my_service->inputs);
584#endif
[9]585        freeElements(&current_element);
[1]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
[104]609        if($1!=NULL){
[453]610          char *cen=zStrdup($1);
[104]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);
[1]617#ifdef DEBUG_SERVICE_CONF
[104]618          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]619#endif
[104]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;
[1]626#ifdef DEBUG_SERVICE_CONF
[104]627          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]628#endif
[104]629        }
[1]630      }
631    }
632    else
633      if(current_data==2){
[607]634        wait_outputs=1;
[65]635        if(wait_inputs){
[57]636          if(current_element!=NULL && current_element->name!=NULL){
[65]637            if(my_service->outputs==NULL){
638              my_service->outputs=dupElements(current_element);
639              my_service->outputs->next=NULL;
[1]640            }
641            else{
642#ifdef DEBUG_SERVICE_CONF
643              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
644#endif
[65]645              addToElements(&my_service->outputs,current_element);
[1]646            }
647#ifdef DEBUG_SERVICE_CONF
648            dumpElements(current_element);
[9]649            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
[1]650#endif
651            freeElements(&current_element);
[9]652            free(current_element);
[1]653            current_element=NULL;
654#ifdef DEBUG_SERVICE_CONF
[104]655            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
[1]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);
[104]669            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
[1]670#endif
[104]671            if($1!=NULL){
[453]672              char *cen=zStrdup($1);
[104]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            }
[1]686          }
[65]687
[1]688          current_content=NULL;
689        }
690        else
[65]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);
[92]696#ifdef DEBUG_SERVICE_CONF
[65]697            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
698            dupElements(current_element);
[92]699#endif
[65]700            freeElements(&current_element);
701            free(current_element);
702            current_element=NULL;
[379]703            current_element=(elements*)malloc(ELEMENTS_SIZE);
[453]704            char *cen=zStrdup($1);
[379]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;
[65]717          }
718          else{
[1]719#ifdef DEBUG_SERVICE_CONF
720            fprintf(stderr,"NAME OUT %s\n",$1);
[379]721            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
[1]722#endif
[104]723            if($1!=NULL){
[453]724              char *cen=zStrdup($1);
[379]725              current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
[104]726              cen[strlen(cen)-1]=0;
[9]727#ifdef DEBUG
[104]728              fprintf(stderr,"tmp %s\n",cen);
[9]729#endif
[104]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            }
[1]741          }
[65]742        wait_inputs=false;
[607]743        wait_outputs=1;
[65]744        //wait_outputs=true;
[1]745      }
746  }
747 }
748 ;
749
750%%
751
[607]752/**
753 * Print on stderr the message and the line number of the error which occured.
754 *
755 * @param s the error message
756 */
[114]757void srerror(const char *s)
[1]758{
759  if(debug)
760    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
761}
762
763/**
[607]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
[1]770 */
[465]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  }
[1]777#ifdef DEBUG_SERVICE_CONF
778  fprintf(stderr,"(STARTING)FREE current_element\n");
779#endif
[465]780  if(current_element!=NULL){
781    freeElements(&current_element);
782    free(current_element);
783    current_element=NULL;
784  }
[1]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;
[607]793  wait_outputs=-1;
[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){
[503]803    setMapInMaps(conf,"lenv","message","file not found");
[9]804    return -1;
[1]805  }
806
807  int resultatYYParse = srparse() ;
[476]808
[465]809#ifdef DEBUG_SERVICE_CONF
810  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
[607]811  dumpElements(current_element);
[465]812#endif
[618]813  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
[607]814    if(my_service->outputs==NULL){ 
[1]815#ifdef DEBUG_SERVICE_CONF
[104]816      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
[1]817#endif
818      my_service->outputs=dupElements(current_element);
[9]819      my_service->outputs->next=NULL;
[1]820    }
821    else{
822#ifdef DEBUG_SERVICE_CONF
[104]823      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
[1]824#endif
[9]825      addToElements(&my_service->outputs,current_element);
[1]826    }
827#ifdef DEBUG_SERVICE_CONF
[104]828    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[1]829#endif
830    freeElements(&current_element);
[9]831    free(current_element);
832    current_element=NULL;
[57]833#ifdef DEBUG_SERVICE_CONF
[104]834    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[57]835#endif
[1]836  }
837  if(current_element!=NULL){
838    freeElements(&current_element);
[9]839    free(current_element);
[1]840    current_element=NULL;
841  }
[618]842  int contentOnly=false;
[1]843  if(current_content!=NULL){
[607]844    if(my_service->content==NULL){
845      addMapToMap(&my_service->content,current_content);
[618]846      contentOnly=true;
847      wait_maincontent=false;
[607]848    }
[1]849    freeMap(&current_content);
[9]850    free(current_content);
[1]851    current_content=NULL;
852  }
853  fclose(srin);
854#ifdef DEBUG_SERVICE_CONF
855  dumpService(my_service);
856#endif
[618]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))){
[465]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;
[1]866
[216]867#ifndef WIN32
[9]868  srlex_destroy();
[216]869#endif
[1]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