[1] | 1 | %{ |
---|
| 2 | //====================================================== |
---|
| 3 | /** |
---|
| 4 | * Thx to Jean-Marie CODOL and Naitan GROLLEMUND |
---|
| 5 | * copyright 2009 GeoLabs SARL |
---|
| 6 | * Author : Gérald FENOY |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | //====================================================== |
---|
| 10 | |
---|
| 11 | #include <string> |
---|
| 12 | #include <stdio.h> |
---|
| 13 | #include <ctype.h> |
---|
| 14 | #include <service.h> |
---|
| 15 | #include <vector> |
---|
| 16 | |
---|
| 17 | static int tmp_count=1; |
---|
| 18 | static int defaultsc=0; |
---|
| 19 | static bool wait_maincontent=true; |
---|
| 20 | static bool wait_mainmetadata=false; |
---|
| 21 | static bool wait_metadata=false; |
---|
| 22 | static bool wait_inputs=false; |
---|
| 23 | static bool wait_defaults=false; |
---|
| 24 | static bool wait_supporteds=false; |
---|
| 25 | static bool wait_outputs=false; |
---|
| 26 | static bool wait_data=false; |
---|
| 27 | static int services_c=0; |
---|
| 28 | static service* my_service=NULL; |
---|
| 29 | static map* previous_content=NULL; |
---|
| 30 | static map* current_content=NULL; |
---|
| 31 | static elements* current_element=NULL; |
---|
| 32 | static map* scontent=NULL; |
---|
| 33 | static char* curr_key; |
---|
| 34 | static int debug=0; |
---|
| 35 | static int data=-1; |
---|
| 36 | static int previous_data=0; |
---|
| 37 | static int current_data=0; |
---|
| 38 | static char* myFinalObjectAsJSON="{"; |
---|
| 39 | // namespace |
---|
| 40 | using namespace std; |
---|
| 41 | //====================================================== |
---|
| 42 | |
---|
| 43 | // srerror |
---|
| 44 | void srerror(char *s); |
---|
| 45 | //====================================================== |
---|
| 46 | |
---|
| 47 | // usage () |
---|
| 48 | void usage(void) ; |
---|
| 49 | //====================================================== |
---|
| 50 | |
---|
| 51 | // srdebug |
---|
| 52 | extern int srdebug; |
---|
| 53 | //====================================================== |
---|
| 54 | |
---|
| 55 | extern char srtext[]; |
---|
| 56 | |
---|
| 57 | // srlineno |
---|
| 58 | extern int srlineno; |
---|
| 59 | //====================================================== |
---|
| 60 | |
---|
| 61 | // srin |
---|
| 62 | extern FILE* srin; |
---|
| 63 | //====================================================== |
---|
| 64 | |
---|
| 65 | // srlex |
---|
| 66 | extern int srlex(void); |
---|
| 67 | |
---|
| 68 | vector<char*> lattribute; |
---|
| 69 | |
---|
| 70 | %} |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | %union |
---|
| 75 | {char * s;char* chaine;char* key;char* val;} |
---|
| 76 | |
---|
| 77 | // jetons // |
---|
| 78 | %token <s> ID |
---|
| 79 | %token <s> CHAINE |
---|
| 80 | /* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/ |
---|
| 81 | %token STARTXMLDECL ENDXMLDECL |
---|
| 82 | //====================================================== |
---|
| 83 | /* version="xxx" et encoding="xxx" */ |
---|
| 84 | %token VERSIONDECL ENCODINGDECL SDDECL |
---|
| 85 | //====================================================== |
---|
| 86 | /* < et > */ |
---|
| 87 | %token INFCAR SUPCAR |
---|
| 88 | //====================================================== |
---|
| 89 | /* / = a1 texte "texte" */ |
---|
| 90 | %token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID |
---|
| 91 | %type <chaine> PAIR |
---|
| 92 | %type <chaine> EPAIR |
---|
| 93 | %type <chaine> SPAIR |
---|
| 94 | //====================================================== |
---|
| 95 | /* <!-- xxx -> <? xxx yyy ?> */ |
---|
| 96 | %token PI PIERROR /** COMMENT **/ |
---|
| 97 | //====================================================== |
---|
| 98 | /* <!-- xxx -> <? xxx yyy ?> */ |
---|
| 99 | %token ERREURGENERALE CDATA WHITESPACE NEWLINE |
---|
| 100 | %type <s> STag |
---|
| 101 | %type <s> ETag |
---|
| 102 | %type <s> ANID |
---|
| 103 | //====================================================== |
---|
| 104 | // %start |
---|
| 105 | //====================================================== |
---|
| 106 | |
---|
| 107 | %% |
---|
| 108 | // document <//=== |
---|
| 109 | //====================================================== |
---|
| 110 | // regle 1 |
---|
| 111 | // on est a la racine du fichier xml |
---|
| 112 | //====================================================== |
---|
| 113 | document |
---|
| 114 | : miscetoile element miscetoile {} |
---|
| 115 | | contentetoile processid contentetoile document {} |
---|
| 116 | ; |
---|
| 117 | |
---|
| 118 | miscetoile |
---|
| 119 | : miscetoile PIERROR { srerror("processing instruction begining with <?xml ?> impossible\n");} |
---|
| 120 | | miscetoile PI {} |
---|
| 121 | | {} |
---|
| 122 | ; |
---|
| 123 | // element |
---|
| 124 | //====================================================== |
---|
| 125 | // regle 39 |
---|
| 126 | // OUVRANTE CONTENU FERMANTE obligatoirement |
---|
| 127 | // ou neutre |
---|
| 128 | // on ne peut pas avoir Epsilon |
---|
| 129 | // un fichier xml ne peut pas etre vide ou seulement avec un prolog |
---|
| 130 | //====================================================== |
---|
| 131 | element |
---|
| 132 | : STag contentetoile ETag |
---|
| 133 | { |
---|
| 134 | if (strcmp($1,$3) != 0) |
---|
| 135 | { |
---|
| 136 | //srerror("Opening and ending tag mismatch"); |
---|
| 137 | fprintf(stderr,"Opening and ending tag mismatch\n ::details : tag '%s' et '%s' \n",$1,$3); |
---|
| 138 | lattribute.clear(); |
---|
| 139 | //return 1; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | // pour neutre |
---|
| 143 | // on a rien a faire, meme pas renvoyer l identificateur de balise |
---|
| 144 | // vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle . |
---|
| 145 | | EmptyElemTag {} |
---|
| 146 | ; |
---|
| 147 | //====================================================== |
---|
| 148 | // STag |
---|
| 149 | //====================================================== |
---|
| 150 | // regle 40 |
---|
| 151 | // BALISE OUVRANTE |
---|
| 152 | // on est obligé de faire appel a infcar et supcar |
---|
| 153 | // pour acceder aux start conditions DANSBALISE et INITIAL |
---|
| 154 | //====================================================== |
---|
| 155 | STag |
---|
| 156 | : INFCAR ID Attributeetoile SUPCAR |
---|
| 157 | { |
---|
| 158 | /* l'astuce consiste a vider le contenu du vector ici !! */ |
---|
| 159 | /* parce que cet element est reconnu AVANT la balise fermante */ |
---|
| 160 | /* et APRES l'analyse des eventuelles balises internes ou successeur */ |
---|
| 161 | lattribute.clear(); |
---|
| 162 | |
---|
| 163 | if(my_service->content==NULL){ |
---|
| 164 | #ifdef DEBUG_SERVICE_CONF |
---|
| 165 | fprintf(stderr,"NO CONTENT\n"); |
---|
| 166 | #endif |
---|
| 167 | //addMapToMap(&my_service->content,current_content); |
---|
| 168 | //freeMap(¤t_content); |
---|
| 169 | my_service->content=current_content; |
---|
| 170 | current_content=NULL; |
---|
| 171 | my_service->metadata=NULL; |
---|
| 172 | wait_maincontent=false; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | if(strcmp($2,"DataInputs")==0){ |
---|
| 176 | if(wait_mainmetadata==true){ |
---|
| 177 | if(my_service->metadata==NULL) |
---|
| 178 | my_service->metadata=current_content; |
---|
| 179 | else{ |
---|
| 180 | addMapToMap(&my_service->metadata,current_content); |
---|
| 181 | freeMap(¤t_content); |
---|
| 182 | } |
---|
| 183 | current_content=NULL; |
---|
| 184 | } |
---|
| 185 | if(current_element==NULL){ |
---|
| 186 | #ifdef DEBUG_SERVICE_CONF |
---|
| 187 | fprintf(stderr,"(DATAINPUTS - 184) FREE current_element\n"); |
---|
| 188 | #endif |
---|
| 189 | freeElements(¤t_element); |
---|
| 190 | free(current_element); |
---|
| 191 | current_element=NULL; |
---|
| 192 | #ifdef DEBUG_SERVICE_CONF |
---|
| 193 | fprintf(stderr,"(DATAINPUTS - 186) ALLOCATE current_element\n"); |
---|
| 194 | #endif |
---|
| 195 | current_element=NULL; |
---|
| 196 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
---|
| 197 | current_element->name=NULL; |
---|
| 198 | current_element->content=NULL; |
---|
| 199 | current_element->metadata=NULL; |
---|
| 200 | current_element->format=NULL; |
---|
| 201 | current_element->defaults=NULL; |
---|
| 202 | current_element->supported=NULL; |
---|
| 203 | current_element->next=NULL; |
---|
| 204 | } |
---|
| 205 | wait_inputs=true; |
---|
| 206 | current_data=1; |
---|
| 207 | previous_data=1; |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | if(strcmp($2,"DataOutputs")==0){ |
---|
| 211 | if(wait_inputs==true){ |
---|
| 212 | #ifdef DEBUG_SERVICE_CONF |
---|
| 213 | fprintf(stderr,"(DATAOUTPUTS) DUP INPUTS current_element\n"); |
---|
| 214 | #endif |
---|
| 215 | if(my_service->inputs==NULL) |
---|
| 216 | my_service->inputs=dupElements(current_element); |
---|
| 217 | else |
---|
| 218 | addToElements(my_service->inputs,current_element); |
---|
| 219 | #ifdef DEBUG_SERVICE_CONF |
---|
| 220 | dumpElements(current_element); |
---|
| 221 | dumpElements(my_service->inputs); |
---|
| 222 | fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n"); |
---|
| 223 | #endif |
---|
| 224 | freeElements(¤t_element); |
---|
| 225 | free(current_element); |
---|
| 226 | current_element=NULL; |
---|
| 227 | wait_inputs=false; |
---|
| 228 | } |
---|
| 229 | if(current_element==NULL){ |
---|
| 230 | #ifdef DEBUG_SERVICE_CONF |
---|
| 231 | fprintf(stderr,"(DATAOUTPUTS - 206) ALLOCATE current_element (%s)\n",$2); |
---|
| 232 | #endif |
---|
| 233 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
---|
| 234 | current_element->name=NULL; |
---|
| 235 | current_element->content=NULL; |
---|
| 236 | current_element->metadata=NULL; |
---|
| 237 | current_element->format=NULL; |
---|
| 238 | current_element->defaults=NULL; |
---|
| 239 | current_element->supported=NULL; |
---|
| 240 | current_element->next=NULL; |
---|
| 241 | } |
---|
| 242 | wait_outputs=true; |
---|
| 243 | current_data=2; |
---|
| 244 | previous_data=1; |
---|
| 245 | } |
---|
| 246 | else |
---|
| 247 | if(strcmp($2,"MetaData")==0){ |
---|
| 248 | current_data=3; |
---|
| 249 | if(current_element!=NULL){ |
---|
| 250 | wait_metadata=true; |
---|
| 251 | #ifdef DEBUG_SERVICE_CONF |
---|
| 252 | fprintf(stderr,"add current_content to current_element->content\n"); |
---|
| 253 | fprintf(stderr,"LINE 247"); |
---|
| 254 | #endif |
---|
| 255 | addMapToMap(¤t_element->content,current_content); |
---|
| 256 | freeMap(¤t_content); |
---|
| 257 | free(current_content); |
---|
| 258 | } |
---|
| 259 | else{ |
---|
| 260 | wait_mainmetadata=true; |
---|
| 261 | } |
---|
| 262 | current_content=NULL; |
---|
| 263 | } |
---|
| 264 | else |
---|
| 265 | if(strcmp($2,"ComplexData")==0 || strcmp($2,"LiteralData")==0 |
---|
| 266 | || strcmp($2,"ComplexOutput")==0 || strcmp($2,"LiteralOutput")==0){ |
---|
| 267 | current_data=4; |
---|
| 268 | if(wait_metadata==true){ |
---|
| 269 | if(current_content!=NULL){ |
---|
| 270 | current_element->metadata=current_content; |
---|
| 271 | current_element->next=NULL; |
---|
| 272 | current_element->format=$2; |
---|
| 273 | current_element->defaults=NULL; |
---|
| 274 | } |
---|
| 275 | }else{ // No MainMetaData |
---|
| 276 | //addMapToMap(¤t_element->content,current_content); |
---|
| 277 | //freeMap(¤t_content); |
---|
| 278 | //free(current_content); |
---|
| 279 | current_element->content=current_content; |
---|
| 280 | current_element->metadata=NULL; |
---|
| 281 | current_element->next=NULL; |
---|
| 282 | current_element->format=$2; |
---|
| 283 | current_element->defaults=NULL; |
---|
| 284 | } |
---|
| 285 | current_content=NULL; |
---|
| 286 | wait_metadata=false; |
---|
| 287 | } |
---|
| 288 | else |
---|
| 289 | if(strcmp($2,"Default")==0){ |
---|
| 290 | wait_defaults=true; |
---|
| 291 | current_data=5; |
---|
| 292 | } |
---|
| 293 | else |
---|
| 294 | if(strcmp($2,"Supported")==0){ |
---|
| 295 | wait_supporteds=true; |
---|
| 296 | if(wait_defaults==true){ |
---|
| 297 | defaultsc++; |
---|
| 298 | freeMap(¤t_content); |
---|
| 299 | current_content=NULL; |
---|
| 300 | } |
---|
| 301 | current_data=5; |
---|
| 302 | } |
---|
| 303 | #ifdef DEBUG_SERVICE_CONF |
---|
| 304 | printf("* Identifiant : %s\n",$2); |
---|
| 305 | #endif |
---|
| 306 | |
---|
| 307 | /* et on renvoie l'identifiant de balise afin de pouvoir le comparer */ |
---|
| 308 | /* avec la balise jumelle fermante ! */ |
---|
| 309 | $$ = $2 ; |
---|
| 310 | } |
---|
| 311 | ; |
---|
| 312 | //====================================================== |
---|
| 313 | // Attributeetoile |
---|
| 314 | //====================================================== |
---|
| 315 | // regle 41 |
---|
| 316 | // une liste qui peut etre vide d'attributs |
---|
| 317 | // utiliser la récursivité a gauche |
---|
| 318 | //====================================================== |
---|
| 319 | Attributeetoile |
---|
| 320 | : Attributeetoile attribute {} |
---|
| 321 | | {/* Epsilon */} |
---|
| 322 | ; |
---|
| 323 | //====================================================== |
---|
| 324 | // attribute |
---|
| 325 | //====================================================== |
---|
| 326 | // regle 41 |
---|
| 327 | // un attribut est compose d'un identifiant |
---|
| 328 | // d'un "=" |
---|
| 329 | // et d'une définition de chaine de caractere |
---|
| 330 | // ( "xxx" ou 'xxx' ) |
---|
| 331 | //====================================================== |
---|
| 332 | attribute |
---|
| 333 | : ID Eq ATTVALUE |
---|
| 334 | { |
---|
| 335 | // on verifie que les attributst ne sont pas en double |
---|
| 336 | // sinon on ajoute au vector |
---|
| 337 | #ifdef DEBUG_SERVICE_CONF |
---|
| 338 | printf ("attribute : %s\n",$1) ; |
---|
| 339 | #endif |
---|
| 340 | for(int i=0;i < lattribute.size(); i++) |
---|
| 341 | { |
---|
| 342 | if (strcmp($1,lattribute.at(i)) == 0) |
---|
| 343 | { |
---|
| 344 | fprintf (stderr,"attributs identiques : %d -- %s , %s",i,lattribute.at(i),$1) ; |
---|
| 345 | //srerror("attribut redondant !:"); |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | lattribute.push_back($1); |
---|
| 349 | } |
---|
| 350 | ; |
---|
| 351 | //====================================================== |
---|
| 352 | // EmptyElemTag |
---|
| 353 | //====================================================== |
---|
| 354 | // regle 44 |
---|
| 355 | // ICI ON DEFINIT NEUTRE |
---|
| 356 | // on ne renvoie pas de char* |
---|
| 357 | // parce qu'il n'y a pas de comparaisons a faire |
---|
| 358 | // avec un identifiant d'une balise jumelle |
---|
| 359 | //====================================================== |
---|
| 360 | EmptyElemTag |
---|
| 361 | : INFCAR ID Attributeetoile SLASH SUPCAR {lattribute.clear();/* voir Stag */} |
---|
| 362 | ; |
---|
| 363 | //====================================================== |
---|
| 364 | // ETag |
---|
| 365 | //====================================================== |
---|
| 366 | // regle 42 |
---|
| 367 | // BALISE FERMANTE |
---|
| 368 | // les separateurs après ID sont filtrés |
---|
| 369 | //====================================================== |
---|
| 370 | ETag |
---|
| 371 | : INFCAR SLASH ID SUPCAR |
---|
| 372 | { |
---|
| 373 | if(strcmp($3,"DataInputs")==0){ |
---|
| 374 | current_data=1; |
---|
| 375 | } |
---|
| 376 | if(strcmp($3,"DataOutputs")==0){ |
---|
| 377 | current_data=2; |
---|
| 378 | } |
---|
| 379 | if(strcmp($3,"MetaData")==0){ |
---|
| 380 | current_data=previous_data; |
---|
| 381 | } |
---|
| 382 | if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0 |
---|
| 383 | || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){ |
---|
| 384 | current_content=NULL; |
---|
| 385 | } |
---|
| 386 | if(strcmp($3,"Default")==0){ |
---|
| 387 | current_data=previous_data; |
---|
| 388 | if(current_element->defaults==NULL){ |
---|
| 389 | current_element->defaults=(iotype*)malloc(MAP_SIZE); |
---|
| 390 | } |
---|
| 391 | current_element->defaults->content=current_content; |
---|
| 392 | current_element->defaults->next=NULL; |
---|
| 393 | wait_defaults=false; |
---|
| 394 | current_content=NULL; |
---|
| 395 | current_element->supported=NULL; |
---|
| 396 | } |
---|
| 397 | if(strcmp($3,"Supported")==0){ |
---|
| 398 | current_data=previous_data; |
---|
| 399 | if(current_element->supported==NULL){ |
---|
| 400 | current_element->supported=(iotype*)malloc(MAP_SIZE); |
---|
| 401 | current_element->supported->content=current_content; |
---|
| 402 | current_element->supported->next=NULL; |
---|
| 403 | /** |
---|
| 404 | * Need to free this ressource (HERE ?) |
---|
| 405 | free(current_content); |
---|
| 406 | */ |
---|
| 407 | } |
---|
| 408 | else{ |
---|
| 409 | /*current_element->supported->next=(iotype*)malloc(sizeof(iotype*)); |
---|
| 410 | current_element->supported->next->content=NULL; |
---|
| 411 | current_element->supported->next->next=NULL; |
---|
| 412 | iotype* tmp1=current_element->supported; |
---|
| 413 | while(tmp1!=NULL){ |
---|
| 414 | addMapToMap(¤t_element->supported->next->content,current_content); |
---|
| 415 | freeMap(¤t_content); |
---|
| 416 | #ifdef DEBUG_SERVICE_CONF |
---|
| 417 | fprintf(stderr,"LINE 409"); |
---|
| 418 | #endif |
---|
| 419 | free(current_content); |
---|
| 420 | current_content=NULL; |
---|
| 421 | tmp1=tmp1->next; |
---|
| 422 | }*/ |
---|
| 423 | } |
---|
| 424 | current_content=NULL; |
---|
| 425 | } |
---|
| 426 | /* on renvoie l'identifiant de la balise pour pouvoir comparer les 2 */ |
---|
| 427 | /* /!\ une balise fermante n'a pas d'attributs (c.f. : W3C) */ |
---|
| 428 | $$ = $3; |
---|
| 429 | } |
---|
| 430 | ; |
---|
| 431 | //====================================================== |
---|
| 432 | // contentetoile |
---|
| 433 | //====================================================== |
---|
| 434 | // regle 43 |
---|
| 435 | // ENTRE 2 BALISES |
---|
| 436 | // entre 2 balises, on peut avoir : |
---|
| 437 | // --- OUVRANTE CONTENU FERMANTE (recursivement !) |
---|
| 438 | // --- DU TEXTE quelconque |
---|
| 439 | // --- COMMENTS |
---|
| 440 | // --- DES PROCESSES INSTRUCTIONS |
---|
| 441 | // --- /!\ il peut y avoir une processing instruction invalide ! <?xml |
---|
| 442 | // --- EPSILON |
---|
| 443 | // ### et/ou tout ca a la suite en nombre indeterminé |
---|
| 444 | // ### donc c'est un operateur etoile (*) |
---|
| 445 | //====================================================== |
---|
| 446 | contentetoile |
---|
| 447 | : contentetoile element {} |
---|
| 448 | | contentetoile PIERROR {srerror("processing instruction <?xml ?> impossible\n");} |
---|
| 449 | | contentetoile PI {} |
---|
| 450 | ///// on filtre les commentaires | contentetoile comment {} |
---|
| 451 | | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/} |
---|
| 452 | | contentetoile pair {} |
---|
| 453 | | contentetoile processid {} |
---|
| 454 | | contentetoile texteinterbalise {} |
---|
| 455 | | contentetoile CDATA {} |
---|
| 456 | | {/* Epsilon */} |
---|
| 457 | ; |
---|
| 458 | //====================================================== |
---|
| 459 | // texteinterbalise |
---|
| 460 | //====================================================== |
---|
| 461 | // regle 14 |
---|
| 462 | // DU TEXTE quelconque |
---|
| 463 | // c'est du CHARDATA |
---|
| 464 | // il y a eut un probleme avec ID, |
---|
| 465 | // on a mis des starts conditions, |
---|
| 466 | // maintenant on croise les ID dans les dbalises |
---|
| 467 | // et des CHARDATA hors des balises |
---|
| 468 | //====================================================== |
---|
| 469 | texteinterbalise |
---|
| 470 | : CHARDATA {} |
---|
| 471 | ; |
---|
| 472 | //====================================================== |
---|
| 473 | |
---|
| 474 | pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n"); } |
---|
| 475 | | EPAIR { |
---|
| 476 | #ifdef DEBUG_SERVICE_CONF |
---|
| 477 | fprintf(stderr,"EPAIR FOUND !! \n"); |
---|
| 478 | fprintf(stderr,"[%s=>%s]\n",curr_key,$1); |
---|
| 479 | fprintf(stderr,"[ZOO: service_conf.y line 482 free(%s)]\n",curr_key); |
---|
| 480 | dumpMap(current_content); |
---|
| 481 | fflush(stderr); |
---|
| 482 | #endif |
---|
| 483 | if(current_content==NULL){ |
---|
| 484 | #ifdef DEBUG_SERVICE_CONF |
---|
| 485 | fprintf(stderr,"[ZOO: service_conf.y line 482 free(%s)]\n",curr_key); |
---|
| 486 | #endif |
---|
| 487 | current_content=createMap(curr_key,$1); |
---|
| 488 | #ifdef DEBUG_SERVICE_CONF |
---|
| 489 | fprintf(stderr,"[ZOO: service_conf.y line 482 free(%s)]\n",curr_key); |
---|
| 490 | #endif |
---|
| 491 | //current_content->next=NULL; |
---|
| 492 | } |
---|
| 493 | else{ |
---|
| 494 | #ifdef DEBUG_SERVICE_CONF |
---|
| 495 | dumpMap(current_content); |
---|
| 496 | fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1); |
---|
| 497 | |
---|
| 498 | #endif |
---|
| 499 | //map* tmp1=createMap(curr_key,$1); |
---|
| 500 | addToMap(current_content,curr_key,$1); |
---|
| 501 | //freeMap(&tmp1); |
---|
| 502 | //free(tmp1); |
---|
| 503 | #ifdef DEBUG_SERVICE_CONF |
---|
| 504 | fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1); |
---|
| 505 | #endif |
---|
| 506 | } |
---|
| 507 | //free(curr_key); |
---|
| 508 | curr_key=NULL; |
---|
| 509 | #ifdef DEBUG_SERVICE_CONF |
---|
| 510 | fprintf(stderr,"EPAIR FOUND !! \n"); |
---|
| 511 | fprintf(stderr,"[%s=>%s]\n",curr_key,$1); |
---|
| 512 | fprintf(stderr,"[ZOO: service_conf.y line 505 free(%s)]\n",curr_key); |
---|
| 513 | fflush(stderr); |
---|
| 514 | #endif |
---|
| 515 | } |
---|
| 516 | | SPAIR { curr_key=$1; if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); } |
---|
| 517 | ; |
---|
| 518 | |
---|
| 519 | |
---|
| 520 | processid |
---|
| 521 | : ANID { |
---|
| 522 | if(data==-1){ |
---|
| 523 | data=1; |
---|
| 524 | my_service->name=$1; |
---|
| 525 | my_service->content=NULL; |
---|
| 526 | my_service->metadata=NULL; |
---|
| 527 | my_service->inputs=NULL; |
---|
| 528 | my_service->outputs=NULL; |
---|
| 529 | } else { |
---|
| 530 | if(current_data==1){ |
---|
| 531 | if(my_service->content!=NULL && current_element->name!=NULL){ |
---|
| 532 | //fprintf(stderr,"ELEMENT (%s)",current_element->name); |
---|
| 533 | if(my_service->inputs==NULL){ |
---|
| 534 | #ifdef DEBUG_SERVICE_CONF |
---|
| 535 | fprintf(stderr,"count (%i) (%s)\n",tmp_count%2,$1); |
---|
| 536 | fflush(stderr); |
---|
| 537 | #endif |
---|
| 538 | //if(tmp_count==1){ |
---|
| 539 | #ifdef DEBUG_SERVICE_CONF |
---|
| 540 | fprintf(stderr,"(DATAINPUTS - 464)DUP current_element\n"); |
---|
| 541 | dumpElements(current_element); |
---|
| 542 | #endif |
---|
| 543 | my_service->inputs=dupElements(current_element); |
---|
| 544 | #ifdef DEBUG_SERVICE_CONF |
---|
| 545 | fprintf(stderr,"(DATAINPUTS - 466)FREE current_element\n"); |
---|
| 546 | #endif |
---|
| 547 | freeElements(¤t_element); |
---|
| 548 | current_element=NULL; |
---|
| 549 | tmp_count++; |
---|
| 550 | } |
---|
| 551 | else{ |
---|
| 552 | addToElements(my_service->inputs,current_element); |
---|
| 553 | #ifdef DEBUG_SERVICE_CONF |
---|
| 554 | fprintf(stderr,"(DATAINPUTS - 6)FREE current_element (after adding to allread existing inputs)"); |
---|
| 555 | #endif |
---|
| 556 | freeElements(¤t_element); |
---|
| 557 | } |
---|
| 558 | #ifdef DEBUG_SERVICE_CONF |
---|
| 559 | dumpElements(my_service->inputs); |
---|
| 560 | #endif |
---|
| 561 | free(current_element); |
---|
| 562 | current_element=NULL; |
---|
| 563 | #ifdef DEBUG_SERVICE_CONF |
---|
| 564 | fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n"); |
---|
| 565 | #endif |
---|
| 566 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
---|
| 567 | current_element->name=NULL; |
---|
| 568 | current_element->content=NULL; |
---|
| 569 | current_element->metadata=NULL; |
---|
| 570 | current_element->format=NULL; |
---|
| 571 | current_element->defaults=NULL; |
---|
| 572 | current_element->supported=NULL; |
---|
| 573 | current_element->next=NULL; |
---|
| 574 | } |
---|
| 575 | if(current_element->name==NULL){ |
---|
| 576 | #ifdef DEBUG_SERVICE_CONF |
---|
| 577 | fprintf(stderr,"NAME IN %s (current - %s)\n", |
---|
| 578 | $1,current_element->name); |
---|
| 579 | #endif |
---|
| 580 | wait_inputs=true; |
---|
| 581 | #ifdef DEBUG_SERVICE_CONF |
---|
| 582 | fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n"); |
---|
| 583 | #endif |
---|
| 584 | current_element->name=strdup($1); |
---|
| 585 | #ifdef DEBUG_SERVICE_CONF |
---|
| 586 | fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name); |
---|
| 587 | #endif |
---|
| 588 | current_element->content=NULL; |
---|
| 589 | current_element->metadata=NULL; |
---|
| 590 | current_element->format=NULL; |
---|
| 591 | current_element->defaults=NULL; |
---|
| 592 | current_element->supported=NULL; |
---|
| 593 | current_element->next=NULL; |
---|
| 594 | #ifdef DEBUG_SERVICE_CONF |
---|
| 595 | fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name); |
---|
| 596 | #endif |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | else |
---|
| 600 | if(current_data==2){ |
---|
| 601 | if(wait_inputs==true){ |
---|
| 602 | fprintf(stderr,"dup INPUTS\n"); |
---|
| 603 | if(current_element->name!=NULL){ |
---|
| 604 | if(my_service->inputs==NULL){ |
---|
| 605 | my_service->inputs=dupElements(current_element); |
---|
| 606 | } |
---|
| 607 | else{ |
---|
| 608 | #ifdef DEBUG_SERVICE_CONF |
---|
| 609 | fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name); |
---|
| 610 | #endif |
---|
| 611 | addToElements(my_service->inputs,current_element); |
---|
| 612 | } |
---|
| 613 | #ifdef DEBUG_SERVICE_CONF |
---|
| 614 | dumpElements(current_element); |
---|
| 615 | fprintf(stderr,"(DATAOUTPUTS - 531) FREE current_element\n"); |
---|
| 616 | #endif |
---|
| 617 | freeElements(¤t_element); |
---|
| 618 | free(¤t_element); |
---|
| 619 | #ifdef DEBUG_SERVICE_CONF |
---|
| 620 | fprintf(stderr,"free OUTPUTS\n"); |
---|
| 621 | #endif |
---|
| 622 | current_element=NULL; |
---|
| 623 | #ifdef DEBUG_SERVICE_CONF |
---|
| 624 | fprintf(stderr,"(DATAOUTPUTS - 536) ALLOCATE current_element\n"); |
---|
| 625 | #endif |
---|
| 626 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
---|
| 627 | current_element->name=NULL; |
---|
| 628 | current_element->content=NULL; |
---|
| 629 | current_element->metadata=NULL; |
---|
| 630 | current_element->format=NULL; |
---|
| 631 | current_element->defaults=NULL; |
---|
| 632 | current_element->supported=NULL; |
---|
| 633 | current_element->next=NULL; |
---|
| 634 | } |
---|
| 635 | if(current_element->name==NULL){ |
---|
| 636 | #ifdef DEBUG_SERVICE_CONF |
---|
| 637 | fprintf(stderr,"NAME OUT %s\n",$1); |
---|
| 638 | fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n"); |
---|
| 639 | #endif |
---|
| 640 | current_element->name=strdup($1); |
---|
| 641 | current_element->content=NULL; |
---|
| 642 | current_element->metadata=NULL; |
---|
| 643 | current_element->format=NULL; |
---|
| 644 | current_element->defaults=NULL; |
---|
| 645 | current_element->supported=NULL; |
---|
| 646 | current_element->next=NULL; |
---|
| 647 | } |
---|
| 648 | wait_inputs=false; |
---|
| 649 | current_content=NULL; |
---|
| 650 | } |
---|
| 651 | else |
---|
| 652 | if(current_element->name==NULL){ |
---|
| 653 | #ifdef DEBUG_SERVICE_CONF |
---|
| 654 | fprintf(stderr,"NAME OUT %s\n",$1); |
---|
| 655 | fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n"); |
---|
| 656 | #endif |
---|
| 657 | current_element->name=strdup($1); |
---|
| 658 | current_element->content=NULL; |
---|
| 659 | current_element->metadata=NULL; |
---|
| 660 | current_element->format=NULL; |
---|
| 661 | current_element->defaults=NULL; |
---|
| 662 | current_element->supported=NULL; |
---|
| 663 | current_element->next=NULL; |
---|
| 664 | } |
---|
| 665 | wait_outputs=true; |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | } |
---|
| 669 | ; |
---|
| 670 | |
---|
| 671 | %% |
---|
| 672 | |
---|
| 673 | // srerror |
---|
| 674 | //====================================================== |
---|
| 675 | /* fonction qui affiche l erreur si il y en a une */ |
---|
| 676 | //====================================================== |
---|
| 677 | void srerror(char *s) |
---|
| 678 | { |
---|
| 679 | if(debug) |
---|
| 680 | fprintf(stderr,"\nligne %d : %s\n",srlineno,s); |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | /** |
---|
| 684 | * getServiceFromFile : |
---|
| 685 | * set service given as second parameter with informations extracted from the |
---|
| 686 | * definition file. |
---|
| 687 | */ |
---|
| 688 | int getServiceFromFile(char* file,service** service){ |
---|
| 689 | |
---|
| 690 | freeMap(&previous_content); |
---|
| 691 | previous_content=NULL; |
---|
| 692 | freeMap(¤t_content); |
---|
| 693 | current_content=NULL; |
---|
| 694 | freeMap(&scontent); |
---|
| 695 | #ifdef DEBUG_SERVICE_CONF |
---|
| 696 | fprintf(stderr,"(STARTING)FREE current_element\n"); |
---|
| 697 | #endif |
---|
| 698 | freeElements(¤t_element); |
---|
| 699 | current_element=NULL; |
---|
| 700 | #ifdef DEBUG_SERVICE_CONF |
---|
| 701 | fprintf(stderr,"(STARTING)FREE my_service\n"); |
---|
| 702 | #endif |
---|
| 703 | //freeService(&my_service); |
---|
| 704 | //free(my_service); |
---|
| 705 | #ifdef DEBUG_SERVICE_CONF |
---|
| 706 | fprintf(stderr,"(STARTING)FREE my_service done\n"); |
---|
| 707 | #endif |
---|
| 708 | my_service=NULL; |
---|
| 709 | scontent=NULL; |
---|
| 710 | |
---|
| 711 | wait_maincontent=true; |
---|
| 712 | wait_mainmetadata=false; |
---|
| 713 | wait_metadata=false; |
---|
| 714 | wait_inputs=false; |
---|
| 715 | wait_defaults=false; |
---|
| 716 | wait_supporteds=false; |
---|
| 717 | wait_outputs=false; |
---|
| 718 | wait_data=false; |
---|
| 719 | data=-1; |
---|
| 720 | previous_data=1; |
---|
| 721 | current_data=0; |
---|
| 722 | |
---|
| 723 | my_service=*service; |
---|
| 724 | |
---|
| 725 | srin = fopen(file,"r"); |
---|
| 726 | if (srin==NULL){ |
---|
| 727 | fprintf(stderr,"error : le fichier specifie n'existe pas ou n'est pas accessible en lecture\n") ; |
---|
| 728 | return 22; |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | //printf(" "); |
---|
| 732 | int resultatYYParse = srparse() ; |
---|
| 733 | |
---|
| 734 | if(wait_outputs==true && current_element->name!=NULL){ |
---|
| 735 | if(my_service->outputs==NULL){ |
---|
| 736 | #ifdef DEBUG_SERVICE_CONF |
---|
| 737 | fprintf(stderr,"(DATAOUTPUTS - 623) DUP current_element\n"); |
---|
| 738 | #endif |
---|
| 739 | my_service->outputs=dupElements(current_element); |
---|
| 740 | current_element=NULL; |
---|
| 741 | } |
---|
| 742 | else{ |
---|
| 743 | #ifdef DEBUG_SERVICE_CONF |
---|
| 744 | fprintf(stderr,"(DATAOUTPUTS - 628) COPY current_element\n"); |
---|
| 745 | #endif |
---|
| 746 | addToElements(my_service->outputs,current_element); |
---|
| 747 | } |
---|
| 748 | #ifdef DEBUG_SERVICE_CONF |
---|
| 749 | fprintf(stderr,"(DATAOUTPUTS - 631) FREE current_element\n"); |
---|
| 750 | #endif |
---|
| 751 | freeElements(¤t_element); |
---|
| 752 | } |
---|
| 753 | if(current_element!=NULL){ |
---|
| 754 | freeElements(¤t_element); |
---|
| 755 | fprintf(stderr,"LINE 709"); |
---|
| 756 | //free(current_element); |
---|
| 757 | current_element=NULL; |
---|
| 758 | } |
---|
| 759 | if(current_content!=NULL){ |
---|
| 760 | freeMap(¤t_content); |
---|
| 761 | fprintf(stderr,"LINE 715"); |
---|
| 762 | //free(current_content); |
---|
| 763 | current_content=NULL; |
---|
| 764 | } |
---|
| 765 | fclose(srin); |
---|
| 766 | #ifdef DEBUG_SERVICE_CONF |
---|
| 767 | dumpService(my_service); |
---|
| 768 | #endif |
---|
| 769 | *service=my_service; |
---|
| 770 | |
---|
| 771 | return resultatYYParse; |
---|
| 772 | } |
---|