Changeset 621 for trunk/zoo-project/zoo-kernel
- Timestamp:
- Apr 9, 2015, 5:23:06 AM (10 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/Makefile.in
r601 r621 32 32 ulinet.o: ulinet.c 33 33 gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c 34 35 request_parser.o: request_parser.c request_parser.h 36 gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c 34 37 35 38 service_internal.o: service_internal.c service.h mimetypes.h … … 72 75 g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c -fno-common -DPIC -o zoo_service_loader.o 73 76 74 zoo_loader.cgi: version.h zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE}77 zoo_loader.cgi: version.h zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o request_parser.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} 75 78 g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${RUBYCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c -fno-common -DPIC -o zoo_loader.o 76 g++ ${JSCFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}79 g++ ${JSCFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS} 77 80 78 81 zcfg2yaml: zcfg2yaml.c ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${JS_FILE} ${RUBY_FILE} ${YAML_FILE} -
trunk/zoo-project/zoo-kernel/main_conf_read.l
r378 r621 1 /* Line number from bison */ 1 /* 2 * Zoo main configuration file parser 3 * 4 * Author : Gérald FENOY 5 * 6 * Copyright (c) 209-2015 GeoLabs SARL 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 */ 2 26 %option yylineno 3 27 4 28 %{ 5 //======================================================6 /**7 Zoo main configuration file parser8 **/9 //======================================================10 11 29 12 30 #include <string.h> 13 31 #include "main_conf_read.tab.h" 14 32 static int affichetrace = 0 ; 15 static int attentionImpossibleDeTrouverXMLDeclapres = 0 ;16 static int attentionImpossibleDeTrouverPIapres = 0 ;17 33 18 34 %} 19 20 21 S [ \t\r\n]+22 23 CharRef "&#"[0-9]+";"|"&#x"[0-9a-fA-F]+";"24 25 egalevolue {S}?"="{S}?26 27 Name ([_:]|[\x41-\x5A]|[\x61-\x7A]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\xFF])(([\x41-\x5A]|[\x61-\x7A]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\xFF])|[0-9.\-_:])*28 29 chardata [^<]*30 35 31 36 attname [a-zA-Z0-9_\-:]+ … … 33 38 attvalue1 [%\*,;@a-zA-Z0-9_\-.:" "\"\'/\\\(\)\+\x41-\xff]+ 34 39 35 attvalue \"[^"]*\"|\'[^']*\'36 37 virgule [,]+38 39 whitespace [ ]{0,}40 40 whitesp [ ] 41 41 newline [\r\n]|[\n] 42 newlines [\r\n]{1,}|[\n]{1,}43 44 45 42 46 43 %x DANSBALISE HORSBALISE PAIRSTART 47 48 49 50 44 51 45 %% … … 65 59 <PAIRSTART,INITIAL,HORSBALISE,DANSBALISE>{newline}+{whitesp}* {if (affichetrace==1) printf ("\n\nNEWLINE 2\n") ; BEGIN(INITIAL); return NEWLINE;} 66 60 67 <INITIAL>"<?"[Xx][Mm][Ll] { if (attentionImpossibleDeTrouverXMLDeclapres == 1 || attentionImpossibleDeTrouverPIapres == 1) { printf("\nerror : LINE %d : comment ot PI before xml declaration\n",yylineno); exit (10) ; } ; if (affichetrace==1) printf ("\n\nSTARTXMLDECL:%s\n",yytext) ;return STARTXMLDECL;}68 69 <INITIAL>"version"{egalevolue}\"1.0\"|"version"{egalevolue}\'1.0\' {if (affichetrace==1) printf ("\n\nVERSIONDECL:%s\n",yytext) ;return VERSIONDECL;}70 <INITIAL>"version"{egalevolue}\"[^"]*\"|"version"{egalevolue}\'[^']*\' {/* erreur de version encoding */ printf("\nerror : LINE %d : XML Version not supported : %s\n",yylineno,yytext); exit (9) ; }71 72 73 <INITIAL>"encoding"{egalevolue}\"[Ii][Ss][Oo]"-8859-1"\"|"encoding"{egalevolue}\'[Ii][Ss][Oo]"-8859-1"\' {if (affichetrace==1) printf ("\n\nENCODINGDECL:%s\n",yytext) ; return ENCODINGDECL;}74 <INITIAL>"encoding"{egalevolue}\"[^"]*\"|"encoding"{egalevolue}\'[^']*\' {/* erreur de version encoding */ printf("\nerror : LINE %d : encoding version not supported : %s\n",yylineno,yytext); exit (8) ; }75 76 77 <INITIAL>"standalone"{egalevolue}\"yes\"|"standalone"{egalevolue}\'yes\'|"standalone"{egalevolue}\"no\"|"standalone"{egalevolue}\'no\' {if (affichetrace==1) printf ("\n\nSDDECL:%s\n",yytext) ; return SDDECL;}78 79 <INITIAL>"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\'|"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\' {/* erreur de version encoding */ printf("\nerror : LINE %d : standalone version not supported : %s\n",yylineno,yytext); exit (7) ; }80 81 82 <INITIAL>"?>" {if (affichetrace==1) printf ("\n\nENDXMLDECL:%s\n",yytext) ; BEGIN(HORSBALISE);return ENDXMLDECL;}83 84 85 <DANSBALISE,INITIAL,HORSBALISE>{S} {if (affichetrace==1) printf ("\n\nS:'%s'\n",yytext) ; }86 87 88 <HORSBALISE>"<?"[Xx][Mm][Ll]{S}({S}|{chardata})*"?>"|"<?"[Xx][Mm][Ll]"?>" {if (affichetrace==1) printf ("\n\nPIERROR:%s\n",yytext) ; return PIERROR;}89 <INITIAL,HORSBALISE>"<?"([^xX]|([xX][^mM])|([xX][mM][^lL]))({S}|([^?]|("?"[^>])))*"?>" {attentionImpossibleDeTrouverPIapres=1 ; if (affichetrace==1) printf ("\n\nPI:%s\n",yytext) ; return PI;}90 91 92 <INITIAL,HORSBALISE>{newline}*"<" {if (affichetrace==1) printf ("\n\nINFCAR:%s\n",yytext) ; BEGIN(DANSBALISE);return INFCAR;}93 94 95 <DANSBALISE>">" {if (affichetrace==1) printf ("\n\nSUPCAR:%s\n",yytext) ; BEGIN(HORSBALISE);return SUPCAR;}96 97 98 <DANSBALISE>"/" {if (affichetrace==1) printf ("\n\nSLASH:%s\n",yytext) ; return SLASH;}99 100 101 <DANSBALISE>{egalevolue} {if (affichetrace==1) printf ("\n\nEq:'%s'\n",yytext) ; return Eq;}102 103 104 <DANSBALISE>{Name} {if (affichetrace==1) printf ("\n\nID:%s\n",yytext) ; crlval.s=yytext;return ID;}105 106 107 <DANSBALISE>{attvalue} {if (affichetrace==1) printf ("\n\nATTVALUE:%s\n",yytext) ; return ATTVALUE;}108 109 110 <INITIAL,HORSBALISE>"<!--"([^-]|"-"[^-])*"-->" {attentionImpossibleDeTrouverXMLDeclapres=1; }111 112 113 <INITIAL,DANSBALISE,HORSBALISE>.|\n {if (affichetrace==1)printf("error : LINE %d : character not supported '%s'\n",yylineno,yytext); }114 115 61 %% 116 62 -
trunk/zoo-project/zoo-kernel/main_conf_read.y
r607 r621 1 %{2 1 /* 3 2 * Zoo main configuration file parser 3 * 4 * Author : Gérald FENOY 5 * 6 * Copyright (c) 209-2015 GeoLabs SARL 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 4 25 */ 26 %{ 5 27 #include <service.h> 6 28 … … 28 50 %} 29 51 52 %union { char* s;char* chaine; char* key;char* val;} 30 53 31 32 //======================================================33 /* le type des lval des jetons et des elements non terminaux bison */34 //======================================================35 %union { char* s;char* chaine; char* key;char* val;}36 //======================================================37 38 // jetons //39 //======================================================40 /* les jetons que l on retrouve dans FLEX */41 //======================================================42 /* texte on a besoin de récupérer une valeur char* pour la comparer */43 54 %token <s> ID 44 55 %token <s> CHAINE 45 /* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/ 46 %token STARTXMLDECL ENDXMLDECL 47 //====================================================== 48 /* version="xxx" et encoding="xxx" */ 49 %token VERSIONDECL ENCODINGDECL SDDECL 50 //====================================================== 51 /* < et > */ 52 %token INFCAR SUPCAR 53 //====================================================== 54 /* / = a1 texte "texte" */ 55 %token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR EPAIRS ANID 56 57 %token PAIR SPAIR EPAIR EPAIRS ANID 56 58 %type <chaine> PAIR 57 59 %type <chaine> EPAIRS … … 59 61 %type <chaine> SPAIR 60 62 61 //====================================================== 62 /* <!-- xxx -> <? xxx yyy ?> */ 63 %token PI PIERROR /** COMMENT **/ 64 //====================================================== 65 /* <!-- xxx -> <? xxx yyy ?> */ 66 %token ERREURGENERALE CDATA WHITESPACE NEWLINE 67 //====================================================== 68 // non terminaux typés 69 //====================================================== 70 /* elements non terminaux de type char * */ 71 /* uniquement ceux qui devrons etre comparés */ 72 //====================================================== 73 %type <s> STag 74 %type <s> ETag 63 %token WHITESPACE NEWLINE 64 75 65 %type <s> ANID 76 //======================================================77 // %start78 //======================================================79 66 80 67 %% 81 // document <//=== 82 //====================================================== 83 // regle 1 84 // on est a la racine du fichier xml 85 //====================================================== 68 86 69 document 87 : miscetoile elementmiscetoile {}70 : miscetoile miscetoile {} 88 71 | contentetoile processid contentetoile document {} 89 72 ; 90 73 91 74 miscetoile 92 : miscetoile PIERROR {crerror("processing instruction begining with <?xml ?> impossible\n");} 93 | miscetoile PI {} 94 | {} 75 : {} 95 76 ; 96 // element97 //======================================================98 // regle 3999 // OUVRANTE CONTENU FERMANTE obligatoirement100 // ou neutre101 // on ne peut pas avoir Epsilon102 // un fichier xml ne peut pas etre vide ou seulement avec un prolog103 //======================================================104 element105 : STag contentetoile ETag106 {107 /* les non terminaux rendent les valeurs de leur identifiants de balise */108 /* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */109 /* de string */110 if (strcmp($1,$3) != 0)111 {112 crerror("Opening and ending tag mismatch");113 printf("\n ::details : tag '%s' et '%s' \n",$1,$3);114 return 1;115 // on retourne different de 0116 // sinon yyparse rendra 0117 // et dans le main on croira a le fichier xml est valide !118 }119 }120 // pour neutre121 // on a rien a faire, meme pas renvoyer l identificateur de balise122 // vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .123 | EmptyElemTag {}124 ;125 //======================================================126 // STag127 //======================================================128 // regle 40129 // BALISE OUVRANTE130 // on est obligé de faire appel a infcar et supcar131 // pour acceder aux start conditions DANSBALISE et INITIAL132 //======================================================133 STag134 : INFCAR ID Attributeetoile SUPCAR135 {136 77 137 #ifdef DEBUG138 printf("* Identifiant : %s\n",$2);139 #endif140 141 $$ = $2 ;142 }143 ;144 //======================================================145 // Attributeetoile146 //======================================================147 // regle 41148 // une liste qui peut etre vide d'attributs149 // utiliser la récursivité a gauche150 //======================================================151 78 Attributeetoile 152 : Attributeetoile attribute{}79 : Attributeetoile {} 153 80 | {/* Epsilon */} 154 81 ; 155 //====================================================== 156 // attribute 157 //====================================================== 158 // regle 41 159 // un attribut est compose d'un identifiant 160 // d'un "=" 161 // et d'une définition de chaine de caractere 162 // ( "xxx" ou 'xxx' ) 163 //====================================================== 164 attribute 165 : ID Eq ATTVALUE 166 { 167 // on verifie que les attributst ne sont pas en double 168 // sinon on ajoute au vector 169 } 170 ; 171 //====================================================== 172 // EmptyElemTag 173 //====================================================== 174 // regle 44 175 // ICI ON DEFINIT NEUTRE 176 // on ne renvoie pas de char* 177 // parce qu'il n'y a pas de comparaisons a faire 178 // avec un identifiant d'une balise jumelle 179 //====================================================== 180 EmptyElemTag 181 : INFCAR ID Attributeetoile SLASH SUPCAR {} 182 ; 183 //====================================================== 184 // ETag 185 //====================================================== 186 // regle 42 187 // BALISE FERMANTE 188 // les separateurs après ID sont filtrés 189 //====================================================== 190 ETag 191 : INFCAR SLASH ID SUPCAR 192 { 193 /* on renvoie l'identifiant de la balise pour pouvoir comparer les 2 */ 194 /* /!\ une balise fermante n'a pas d'attributs (c.f. : W3C) */ 195 $$ = $3; 196 } 197 ; 198 //====================================================== 199 // contentetoile 200 //====================================================== 201 // regle 43 202 // ENTRE 2 BALISES 203 // entre 2 balises, on peut avoir : 204 // --- OUVRANTE CONTENU FERMANTE (recursivement !) 205 // --- DU TEXTE quelconque 206 // --- COMMENTS 207 // --- DES PROCESSES INSTRUCTIONS 208 // --- /!\ il peut y avoir une processing instruction invalide ! <?xml 209 // --- EPSILON 210 // ### et/ou tout ca a la suite en nombre indeterminé 211 // ### donc c'est un operateur etoile (*) 212 //====================================================== 82 213 83 contentetoile 214 : contentetoile element {} 215 | contentetoile PIERROR {crerror("processing instruction <?xml ?> impossible\n");} 216 | contentetoile PI {} 217 ///// on filtre les commentaires | contentetoile comment {} 218 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/} 84 : contentetoile NEWLINE {} 219 85 | contentetoile pair {} 220 | contentetoile processid {}221 | contentetoile texteinterbalise {}222 | contentetoile CDATA {}223 86 | {/* Epsilon */} 224 87 ; 225 //======================================================226 // texteinterbalise227 //======================================================228 // regle 14229 // DU TEXTE quelconque230 // c'est du CHARDATA231 // il y a eut un probleme avec ID,232 // on a mis des starts conditions,233 // maintenant on croise les ID dans les dbalises234 // et des CHARDATA hors des balises235 //======================================================236 texteinterbalise237 : CHARDATA {}238 ;239 //======================================================240 88 241 pair: PAIR {curr_key=zStrdup($1); /*printf("START 0 PAIR FOUND !! \n [%s]\n",$1);*/}89 pair: PAIR {curr_key=zStrdup($1);} 242 90 | EPAIR { 243 91 if(current_content==NULL) -
trunk/zoo-project/zoo-kernel/service.h
r618 r621 1261 1261 } 1262 1262 } 1263 1263 1264 1264 /** 1265 1265 * Dump a service on stderr -
trunk/zoo-project/zoo-kernel/service_conf.l
r618 r621 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 */ 1 24 %option noyywrap 2 25 %option yylineno … … 4 27 5 28 %{ 6 //======================================================7 /**8 9 authors : Jean-Marie CODOL, Naitan GROLLEMUND10 11 **/12 //======================================================13 14 29 15 30 #include <string.h> 16 31 #include "service_conf.tab.h" 17 32 18 #ifdef DEBUG_SERVICE_CONF19 int affichetrace = 1;20 #else21 int affichetrace = 0;22 #endif23 24 33 char *lmsg=NULL; 25 int attentionImpossibleDeTrouverXMLDeclapres = 0 ;26 27 int attentionImpossibleDeTrouverPIapres = 0 ;28 34 29 35 %} … … 41 47 42 48 attname [a-zA-Z0-9._\-]+ 43 attvalue1 [#°²θé\^\*\+,; @a-zA-Z0-9%_\-:\:.:" "\"\'/\\\(\)\t\|\$\&>\[\]]+49 attvalue1 [#°²θé\^\*\+,;?!~`ú@a-zA-Z0-9%_\-:\:.:" "\"\'/\\\(\)\t\|\$\&>\[\]]+ 44 50 45 51 attvalue \"[^"]*\"|\'[^']*\'\(\) … … 58 64 %% 59 65 60 "\n" { if (affichetrace==1) fprintf (stderr,"\n\nNEWLINE\n") ;return NEWLINE;}66 "\n" { } 61 67 62 {newline}+{whitesp}* { if (affichetrace==1) fprintf (stderr,"\n\nNEWLINE 1\n") ; return NEWLINE;}68 {newline}+{whitesp}* { return NEWLINE; } 63 69 64 70 <INITIAL,HORSBALISE>"["{attname}"]" { srlval.chaine=yytext;return ANID; } … … 70 76 <PAIRSTART,INITIAL,HORSBALISE>{whitesp}*"="{whitesp}* { BEGIN(PAIRSTART);} 71 77 72 <PAIRSTART,INITIAL,HORSBALISE,DANSBALISE>{newline}+{whitesp}* { BEGIN(INITIAL); return NEWLINE;} 73 74 <INITIAL>"<?"[Xx][Mm][Ll] { if (attentionImpossibleDeTrouverXMLDeclapres == 1 || attentionImpossibleDeTrouverPIapres == 1) {/* il y a eut un commentaire ou une balise applicative avant la declaration xml */ fprintf(stderr,"\nerror : a la ligne %d : il y a eut un commentaire ou un PI avant la declaration xml\n",srlineno); exit (10) ; } ; return STARTXMLDECL;} 75 76 <INITIAL>"version"{egalevolue}\"1.0\"|"version"{egalevolue}\'1.0\' { return VERSIONDECL; } 77 <INITIAL>"version"{egalevolue}\"[^"]*\"|"version"{egalevolue}\'[^']*\' {/* erreur de version encoding */ fprintf(stderr,"\nerror : a la ligne %d : la version xml n est pas reconnue : %s\n",srlineno,yytext); exit (9) ; } 78 79 80 <INITIAL>"encoding"{egalevolue}\"[Ii][Ss][Oo]"-8859-1"\"|"encoding"{egalevolue}\'[Ii][Ss][Oo]"-8859-1"\' { return ENCODINGDECL;} 81 <INITIAL>"encoding"{egalevolue}\"[^"]*\"|"encoding"{egalevolue}\'[^']*\' {/* erreur de version encoding */ fprintf(stderr,"\nerror : a la ligne %d : la version d encodage n est pas reconnue : %s\n",srlineno,yytext); exit (8) ; } 82 83 84 <INITIAL>"standalone"{egalevolue}\"yes\"|"standalone"{egalevolue}\'yes\'|"standalone"{egalevolue}\"no\"|"standalone"{egalevolue}\'no\' { return SDDECL;} 85 86 <INITIAL>"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\'|"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\' { /* erreur de version encoding */ fprintf(stderr,"\nerror : a la ligne %d : la version standalone n est pas reconnue : %s\n",srlineno,yytext); exit (7) ; } 87 88 89 <INITIAL>"?>" { BEGIN(HORSBALISE); return ENDXMLDECL;} 90 78 <PAIRSTART,INITIAL,HORSBALISE>{newline}+{whitesp}* { BEGIN(INITIAL); return NEWLINE;} 91 79 92 80 <DANSBALISE,INITIAL,HORSBALISE>{S} { } 93 94 95 <HORSBALISE>"<?"[Xx][Mm][Ll]{S}({S}|{chardata})*"?>"|"<?"[Xx][Mm][Ll]"?>" { return PIERROR;}96 <INITIAL,HORSBALISE>"<?"([^xX]|([xX][^mM])|([xX][mM][^lL]))({S}|([^?]|("?"[^>])))*"?>" { attentionImpossibleDeTrouverPIapres=1 ; return PI;}97 98 81 99 82 <INITIAL,HORSBALISE>{newline}*"<" { BEGIN(DANSBALISE); return INFCAR;} … … 115 98 116 99 117 <INITIAL,HORSBALISE>"<!--"([^-]|"-"[^-])*"-->" {attentionImpossibleDeTrouverXMLDeclapres=1; }118 119 120 100 <INITIAL,DANSBALISE,HORSBALISE>.|\n {lmsg=(char*)malloc(1024*sizeof(char));sprintf(lmsg,"error: line %d: character not allowed '%s'",srlineno,yytext);fprintf(stderr,"%s \n",lmsg);srlval.chaine=lmsg;fprintf(stderr,"%s \n",lmsg);return -1;} 121 101 -
trunk/zoo-project/zoo-kernel/service_conf.y
r618 r621 1 1 /* 2 * Thx to Jean-Marie CODOL and Naitan GROLLEMUND3 * copyright 2009 GeoLabs SARL4 2 * Author : Gérald FENOY 5 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. 6 23 */ 7 24 %{ … … 64 81 %token <s> ID 65 82 %token <s> CHAINE 66 /* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/ 67 %token STARTXMLDECL ENDXMLDECL 68 69 /* version="xxx" et encoding="xxx" */ 70 %token VERSIONDECL ENCODINGDECL SDDECL 71 72 /* < et > */ 83 73 84 %token INFCAR SUPCAR 74 85 … … 130 141 { 131 142 #ifdef DEBUG_SERVICE_CONF 132 fprintf(stderr," (%s %d) %s\n",__FILE__,__LINE__,$2);143 fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data); 133 144 fflush(stderr); 134 145 dumpMap(current_content); … … 146 157 } 147 158 if(strncasecmp($2,"DataInputs",10)==0){ 148 if(wait_mainmetadata==true && current_content!=NULL){149 addMapToMap(&my_service->metadata,current_content);150 freeMap(¤t_content);151 free(current_content);152 current_content=NULL;153 wait_mainmetadata=false;154 }155 159 if(current_element==NULL){ 156 160 #ifdef DEBUG_SERVICE_CONF … … 255 259 || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){ 256 260 current_data=4; 257 if(wait_metadata==true){ 258 if(current_content!=NULL){ 259 #ifdef DEBUG_SERVICE_CONF 260 fprintf(stderr,"add current_content to current_element->content\n"); 261 fprintf(stderr,"LINE %d",__LINE__); 262 #endif 263 addMapToMap(¤t_element->metadata,current_content); 264 current_element->next=NULL; 265 if($2!=NULL) 266 current_element->format=zStrdup($2); 267 268 current_element->defaults=NULL; 269 current_element->supported=NULL; 270 freeMap(¤t_content); 271 free(current_content); 272 } 273 }else{ 274 // No MainMetaData 275 addMapToMap(¤t_element->content,current_content); 276 freeMap(¤t_content); 277 free(current_content); 278 current_element->metadata=NULL; 279 current_element->next=NULL; 280 if($2!=NULL) 281 current_element->format=zStrdup($2); 282 current_element->defaults=NULL; 283 current_element->supported=NULL; 284 } 261 addMapToMap(¤t_element->content,current_content); 262 freeMap(¤t_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; 285 269 current_content=NULL; 286 wait_metadata=false;287 270 } 288 271 else … … 311 294 // utiliser la récursivité a gauche 312 295 Attributeetoile 313 296 : Attributeetoile attribute {} 314 297 | {/* Epsilon */} 315 298 ; … … 367 350 { 368 351 #ifdef DEBUG_SERVICE_CONF 369 fprintf(stderr," (%s %d)\n",__FILE__,__LINE__);352 fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data); 370 353 #endif 371 354 if(strcmp($3,"DataInputs")==0){ … … 399 382 } 400 383 if(strcmp($3,"MetaData")==0){ 384 if(current_content!=NULL){ 385 #ifdef DEBUG_SERVICE_CONF 386 fprintf(stderr,"add current_content to current_element->content\n"); 387 fprintf(stderr,"LINE %d",__LINE__); 388 #endif 389 if(wait_metadata){ 390 current_element->metadata=NULL; 391 addMapToMap(¤t_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(¤t_content); 402 free(current_content); 403 current_content=NULL; 404 } 401 405 current_data=previous_data; 406 wait_mainmetadata=false; 407 wait_metadata=false; 402 408 } 403 409 if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0 404 410 || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){ 411 if(current_element->format==NULL) 412 current_element->format=zStrdup($3); 405 413 current_content=NULL; 406 414 } … … 497 505 | EPAIR { 498 506 #ifdef DEBUG_SERVICE_CONF 499 fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__); 500 fprintf(stderr,"EPAIR FOUND !! \n"); 507 fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__); 508 fprintf(stderr,"[%s=>%s]\n",curr_key,$1); 509 dumpMap(current_content); 510 fflush(stderr); 511 #endif 512 if($1!=NULL && curr_key!=NULL){ 513 if(current_content==NULL){ 514 #ifdef DEBUG_SERVICE_CONF 515 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); 516 #endif 517 current_content=createMap(curr_key,$1); 518 #ifdef DEBUG_SERVICE_CONF 519 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); 520 #endif 521 } 522 else{ 523 #ifdef DEBUG_SERVICE_CONF 524 dumpMap(current_content); 525 fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1); 526 #endif 527 addToMap(current_content,curr_key,$1); 528 #ifdef DEBUG_SERVICE_CONF 529 fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1); 530 #endif 531 } 532 } 533 #ifdef DEBUG_SERVICE_CONF 501 534 fprintf(stderr,"[%s=>%s]\n",curr_key,$1); 502 535 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); … … 504 537 fflush(stderr); 505 538 #endif 506 if($1!=NULL && curr_key!=NULL){507 if(current_content==NULL){508 #ifdef DEBUG_SERVICE_CONF509 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);510 #endif511 current_content=createMap(curr_key,$1);512 #ifdef DEBUG_SERVICE_CONF513 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);514 #endif515 }516 else{517 #ifdef DEBUG_SERVICE_CONF518 dumpMap(current_content);519 fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);520 #endif521 addToMap(current_content,curr_key,$1);522 #ifdef DEBUG_SERVICE_CONF523 fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);524 #endif525 }526 }527 #ifdef DEBUG_SERVICE_CONF528 fprintf(stderr,"[%s=>%s]\n",curr_key,$1);529 fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);530 dumpMap(current_content);531 fflush(stderr);532 #endif533 539 if(curr_key!=NULL){ 534 540 free(curr_key); … … 543 549 : ANID { 544 550 #ifdef DEBUG_SERVICE_CONF 545 fprintf(stderr," (%s %d)\n",__FILE__,__LINE__);551 fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1); 546 552 #endif 547 553 if(data==-1){ -
trunk/zoo-project/zoo-kernel/service_internal.c
r620 r621 1249 1249 if(tmp1!=NULL) 1250 1250 xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); 1251 else 1252 xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST "1"); 1251 1253 map* tmp3=getMapFromMaps(m,"lenv","level"); 1252 1254 addPrefix(m,tmp3,serv); … … 1301 1303 else{ 1302 1304 if(j>0) 1303 xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); 1305 xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "true"); 1306 else 1307 xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST "1"); 1304 1308 } 1305 1309 } … … 1452 1456 datatype=1; 1453 1457 } 1454 1458 1455 1459 if(strncmp(type,"Input",5)==0){ 1456 1460 … … 1521 1525 const char* bkt; 1522 1526 if ( ( bkt = strchr(pToken, '[') ) != NULL || ( bkt = strchr(pToken, ']') ) != NULL ){ 1523 1524 1525 1527 strncpy( tmpStr, pToken, bkt - pToken ); 1528 tmpStr[bkt - pToken] = '\0'; 1529 } 1526 1530 } 1527 1531 xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr)); … … 1608 1612 1609 1613 } 1610 1611 1614 1612 int oI=0;1613 for(oI=0;oI<13;oI++)1614 1615 int oI=0; 1616 for(oI=0;oI<13;oI++) 1617 if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ 1615 1618 #ifdef DEBUG 1616 printf("DATATYPE DEFAULT ? %s\n",tmp1->name);1617 #endif 1618 if(strcmp(tmp1->name,"asReference")!=0 &&1619 strncasecmp(tmp1->name,"DataType",8)!=0 &&1620 strcasecmp(tmp1->name,"extension")!=0 &&1621 strcasecmp(tmp1->name,"value")!=0 &&1622 strcasecmp(tmp1->name,"AllowedValues")!=0 &&1623 strncasecmp(tmp1->name,"range",5)!=0){1624 if(datatype!=1){1625 char *tmp2=zCapitalize1(tmp1->name);1626 nc9 = xmlNewNode(NULL, BAD_CAST tmp2);1627 free(tmp2);1628 }1629 else{1630 char *tmp2=zCapitalize(tmp1->name);1631 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);1632 free(tmp2);1633 }1634 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));1635 xmlAddChild(nc5,nc9);1636 if(strcasecmp(tmp1->name,"uom")==0)1637 hasUOM1=true;1638 hasUOM=true;1639 }else1619 printf("DATATYPE DEFAULT ? %s\n",tmp1->name); 1620 #endif 1621 if(strcmp(tmp1->name,"asReference")!=0 && 1622 strncasecmp(tmp1->name,"DataType",8)!=0 && 1623 strcasecmp(tmp1->name,"extension")!=0 && 1624 strcasecmp(tmp1->name,"value")!=0 && 1625 strcasecmp(tmp1->name,"AllowedValues")!=0 && 1626 strncasecmp(tmp1->name,"range",5)!=0){ 1627 if(datatype!=1){ 1628 char *tmp2=zCapitalize1(tmp1->name); 1629 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1630 free(tmp2); 1631 } 1632 else{ 1633 char *tmp2=zCapitalize(tmp1->name); 1634 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); 1635 free(tmp2); 1636 } 1637 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1638 xmlAddChild(nc5,nc9); 1639 if(strcasecmp(tmp1->name,"uom")==0) 1640 hasUOM1=true; 1641 hasUOM=true; 1642 }else 1640 1643 1641 tmp1=tmp1->next;1642 1644 tmp1=tmp1->next; 1645 } 1643 1646 1644 1647 … … 1792 1795 } 1793 1796 1794 if( (tmp1=getMap(_tmp->content,"value"))!=NULL){1797 if(_tmp!=NULL && (tmp1=getMap(_tmp->content,"value"))!=NULL){ 1795 1798 nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); 1796 1799 xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); … … 3200 3203 * cf. parseBoundingBox 3201 3204 */ 3202 if( strcasecmp(tmpInputs->format,"BoundingBoxData")==0){3205 if(tmpInputs->format!=NULL && strcasecmp(tmpInputs->format,"BoundingBoxData")==0){ 3203 3206 maps* tmpI=getMaps(*out,tmpInputs->name); 3204 3207 if(tmpI!=NULL){ … … 3518 3521 FILE* fo=fopen(fname,"w+"); 3519 3522 if(fo==NULL){ 3520 #ifdef DEBUG 3523 #ifdef DEBUG 3521 3524 fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno)); 3522 3525 #endif … … 3600 3603 } 3601 3604 for(int i=0;i<atoi(length->value);i++){ 3602 3603 3605 char* fcontent; 3604 3606 char *mimeType=NULL; … … 3608 3610 char vname1[11]; 3609 3611 char sname[9]; 3612 char mname[15]; 3610 3613 char icname[14]; 3611 3614 char xname[16]; … … 3620 3623 sprintf(vname,"value_%d",i); 3621 3624 sprintf(sname,"size_%d",i); 3625 sprintf(mname,"mimeType_%d",i); 3622 3626 sprintf(icname,"isCached_%d",i); 3623 3627 sprintf(xname,"Reference_%d",i); … … 3625 3629 sprintf(cname,"cache_file"); 3626 3630 sprintf(vname,"value"); 3631 sprintf(sname,"size"); 3632 sprintf(mname,"mimeType"); 3627 3633 sprintf(icname,"isCached"); 3628 sprintf(sname,"size");3629 3634 sprintf(xname,"Reference"); 3630 3635 } 3631 3636 3632 3637 map* tmap=getMapFromMaps(*m,"orequests",vname1); 3633 if((tmp1=getMap(content->content,xname))!=NULL && strcasecmp(tmap->value,tmp1->value)==0 ){ 3638 if((tmp1=getMap(content->content,xname))!=NULL /*&& ((tmap!=NULL && strcasecmp(tmap->value,tmp1->value)==0) )*/){ 3639 3634 3640 if(getMap(content->content,icname)==NULL){ 3635 3641 … … 3648 3654 mimeType=strdup("none"); 3649 3655 else 3650 3656 mimeType=strdup(hInternet->ihandle[index].mimeType); 3651 3657 3652 3658 map* tmpMap=getMapOrFill(&content->content,vname,""); … … 3669 3675 } 3670 3676 addToMap(content->content,sname,ltmp1); 3677 addToMap(content->content,mname,mimeType); 3671 3678 addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0); 3672 3679 free(fcontent); 3673 3680 free(mimeType); 3674 dumpMaps(content);3675 3681 index++; 3676 3682 … … 3688 3694 } 3689 3695 return 0; 3696 } 3697 3698 /** 3699 * Add a request in the download queue 3700 * 3701 * @param m the maps containing the settings of the main.cfg file 3702 * @param url the url to add to the queue 3703 */ 3704 void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){ 3705 hInternet->waitingRequests[hInternet->nb]=strdup(url); 3706 if(req) 3707 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); 3708 maps *oreq=getMaps(*m,"orequests"); 3709 if(oreq==NULL){ 3710 oreq=(maps*)malloc(MAPS_SIZE); 3711 oreq->name=zStrdup("orequests"); 3712 oreq->content=createMap("value",url); 3713 oreq->next=NULL; 3714 addMapsToMaps(m,oreq); 3715 freeMaps(&oreq); 3716 free(oreq); 3717 }else{ 3718 setMapArray(oreq->content,"value",hInternet->nb-1,url); 3719 } 3690 3720 } 3691 3721 … … 3734 3764 } 3735 3765 3736 }else{ 3737 hInternet->waitingRequests[hInternet->nb]=strdup(url); 3738 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); 3739 maps *oreq=getMaps(*m,"orequests"); 3740 if(oreq==NULL){ 3741 oreq=(maps*)malloc(MAPS_SIZE); 3742 oreq->name=zStrdup("orequests"); 3743 oreq->content=createMap("value",url); 3744 oreq->next=NULL; 3745 addMapsToMaps(m,oreq); 3746 freeMaps(&oreq); 3747 free(oreq); 3748 }else{ 3749 setMapArray(oreq->content,"value",hInternet->nb-1,url); 3750 } 3766 }else{ 3767 addRequestToQueue(m,hInternet,url,true); 3751 3768 return 0; 3752 3769 } … … 3775 3792 else{ 3776 3793 addToMap(*content,"isCached","true"); 3777 3778 3794 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 3779 3795 if(tmp!=NULL){ -
trunk/zoo-project/zoo-kernel/service_internal.h
r587 r621 216 216 char* isInCache(maps*,char*); 217 217 int runHttpRequests(maps**,maps**,HINTERNET*); 218 void addRequestToQueue(maps**,HINTERNET*,const char*,bool); 218 219 int loadRemoteFile(maps**,map**,HINTERNET*,char*); 219 220 -
trunk/zoo-project/zoo-kernel/ulinet.c
r607 r621 238 238 handle0->ihandle[i].header=NULL; 239 239 } 240 if(handle.post!=NULL) 241 free(handle.post); 240 242 free(handle.mimeType); 241 243 handle.mimeType = NULL; … … 272 274 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 273 275 hInternet->ihandle[hInternet->nb].pabyData = NULL; 276 hInternet->ihandle[hInternet->nb].post = NULL; 274 277 275 278 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL"); … … 321 324 #ifdef MSG_LAF_VERBOSE 322 325 fprintf(stderr,"FROM ULINET !!"); 323 fprintf(stderr,"HEADER : %s\n",lpszHeaders);326 fprintf(stderr,"HEADER : [%s] %d\n",lpszHeaders,dwHeadersLength); 324 327 #endif 325 328 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POST,1); … … 328 331 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_VERBOSE,1); 329 332 #endif 330 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,lpszHeaders); 331 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,dwHeadersLength+1); 333 hInternet->ihandle[hInternet->nb].post=strdup(lpszHeaders); 334 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,hInternet->ihandle[hInternet->nb].post); 335 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength); 332 336 } 333 337 if(hInternet->ihandle[hInternet->nb].header!=NULL) … … 338 342 curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle); 339 343 344 hInternet->ihandle[hInternet->nb].header=NULL; 340 345 ++hInternet->nb; 341 hInternet->ihandle[hInternet->nb].header=NULL;342 346 343 347 #ifdef ULINET_DEBUG -
trunk/zoo-project/zoo-kernel/ulinet.h
r607 r621 48 48 #ifndef true 49 49 #define true 1 50 #define false -150 #define false 0 51 51 #endif 52 52 … … 81 81 unsigned char *pabyData; //!< the downloaded content 82 82 char *mimeType; //!< the mimeType returned by the server 83 char *post; //!< the potential POST XML content 83 84 int hasCacheFile; //!< 1 if we used a cache file 84 85 int nDataLen; //!< the length of the downloaded content -
trunk/zoo-project/zoo-kernel/zoo_loader.c
r607 r621 54 54 55 55 #include "service_internal.h" 56 57 xmlXPathObjectPtr extractFromDoc(xmlDocPtr,const char*); 56 #include "request_parser.h" 57 58 58 int runRequest(map**); 59 59 … … 216 216 * one. 217 217 */ 218 218 219 if(strncasecmp(cgiRequestMethod,"post",4)==0 || 219 220 (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0) … … 226 227 */ 227 228 map* t1=getMap(tmpMap,"request"); 228 if(t1!=NULL && strncasecmp(t1->value,"<",1)==0) {229 if(t1!=NULL && strncasecmp(t1->value,"<",1)==0) { 229 230 addToMap(tmpMap,"xrequest",t1->value); 230 231 xmlInitParser(); -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r620 r621 54 54 55 55 #include "service_internal.h" 56 #include "request_parser.h" 56 57 57 58 #ifdef USE_PYTHON … … 179 180 } 180 181 181 /**182 * Create (or append to) an array valued maps value = "["",""]"183 *184 * @param m the conf maps containing the main.cfg settings185 * @param mo the map to update186 * @param mi the map to append187 * @param elem the elements containing default definitions188 * @return 0 on success, -1 on failure189 */190 int191 appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem)192 {193 maps *tmpMaps = getMaps (mo, mi->name);194 map *tmap = getMapType (tmpMaps->content);195 elements *el = getElements (elem, mi->name);196 int hasEl = 1;197 if (el == NULL)198 hasEl = -1;199 if (tmap == NULL)200 {201 if (hasEl > 0)202 tmap = getMapType (el->defaults->content);203 }204 205 map *testMap = NULL;206 if (hasEl > 0)207 {208 testMap = getMap (el->content, "maxOccurs");209 }210 else211 {212 testMap = createMap ("maxOccurs", "unbounded");213 }214 215 if (testMap != NULL)216 {217 if (strncasecmp (testMap->value, "unbounded", 9) != 0218 && atoi (testMap->value) > 1)219 {220 addMapsArrayToMaps (&mo, mi, tmap->name);221 map* nb=getMapFromMaps(mo,mi->name,"length");222 if (nb!=NULL && atoi(nb->value)>atoi(testMap->value))223 {224 char emsg[1024];225 sprintf (emsg,226 _("The maximum allowed occurrences for <%s> (%i) was exceeded."),227 mi->name, atoi (testMap->value));228 errorException (m, emsg, "InternalError", NULL);229 return -1;230 }231 }232 else233 {234 if (strncasecmp (testMap->value, "unbounded", 9) == 0)235 {236 if (hasEl < 0)237 {238 freeMap (&testMap);239 free (testMap);240 }241 if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0)242 {243 char emsg[1024];244 map *tmpMap = getMap (mi->content, "length");245 sprintf (emsg,246 _247 ("ZOO-Kernel was unable to load your data for %s position %s."),248 mi->name, tmpMap->value);249 errorException (m, emsg, "InternalError", NULL);250 return -1;251 }252 }253 else254 {255 char emsg[1024];256 sprintf (emsg,257 _258 ("The maximum allowed occurrences for <%s> is one."),259 mi->name);260 errorException (m, emsg, "InternalError", NULL);261 return -1;262 }263 }264 }265 return 0;266 }267 182 268 183 /** … … 495 410 (void) closedir (dirp); 496 411 return 1; 497 }498 499 /**500 * Apply XPath Expression on XML document.501 *502 * @param doc the XML Document503 * @param search the XPath expression504 * @return xmlXPathObjectPtr containing the resulting nodes set505 */506 xmlXPathObjectPtr507 extractFromDoc (xmlDocPtr doc, const char *search)508 {509 xmlXPathContextPtr xpathCtx;510 xmlXPathObjectPtr xpathObj;511 xpathCtx = xmlXPathNewContext (doc);512 xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx);513 xmlXPathFreeContext (xpathCtx);514 return xpathObj;515 412 } 516 413 … … 1722 1619 maps *request_input_real_format = NULL; 1723 1620 maps *tmpmaps = request_input_real_format; 1724 map *postRequest = NULL; 1725 postRequest = getMap (request_inputs, "xrequest"); 1726 if (postRequest == NULLMAP) 1727 { 1728 /** 1729 * Parsing outputs provided as KVP 1730 */ 1731 r_inputs = NULL; 1732 #ifdef DEBUG 1733 fprintf (stderr, "OUTPUT Parsing ... \n"); 1734 #endif 1735 r_inputs = getMap (request_inputs, "ResponseDocument"); 1736 if (r_inputs == NULL) 1737 r_inputs = getMap (request_inputs, "RawDataOutput"); 1738 1739 #ifdef DEBUG 1740 fprintf (stderr, "OUTPUT Parsing ... \n"); 1741 #endif 1742 if (r_inputs != NULL) 1743 { 1744 #ifdef DEBUG 1745 fprintf (stderr, "OUTPUT Parsing start now ... \n"); 1746 #endif 1747 char cursor_output[10240]; 1748 char *cotmp = zStrdup (r_inputs->value); 1749 snprintf (cursor_output, 10240, "%s", cotmp); 1750 free (cotmp); 1751 j = 0; 1752 1753 /** 1754 * Put each Output into the outputs_as_text array 1755 */ 1756 char *pToken; 1757 maps *tmp_output = NULL; 1758 #ifdef DEBUG 1759 fprintf (stderr, "OUTPUT [%s]\n", cursor_output); 1760 #endif 1761 pToken = strtok (cursor_output, ";"); 1762 char **outputs_as_text = (char **) malloc (128 * sizeof (char *)); 1763 if (outputs_as_text == NULL) 1764 { 1765 return errorException (m, _("Unable to allocate memory"), 1766 "InternalError", NULL); 1767 } 1768 i = 0; 1769 while (pToken != NULL) 1770 { 1771 #ifdef DEBUG 1772 fprintf (stderr, "***%s***\n", pToken); 1773 fflush (stderr); 1774 fprintf (stderr, "***%s***\n", pToken); 1775 #endif 1776 outputs_as_text[i] = 1777 (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); 1778 if (outputs_as_text[i] == NULL) 1779 { 1780 return errorException (m, _("Unable to allocate memory"), 1781 "InternalError", NULL); 1782 } 1783 snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s", 1784 pToken); 1785 pToken = strtok (NULL, ";"); 1786 i++; 1787 } 1788 for (j = 0; j < i; j++) 1789 { 1790 char *tmp = zStrdup (outputs_as_text[j]); 1791 free (outputs_as_text[j]); 1792 char *tmpc; 1793 tmpc = strtok (tmp, "@"); 1794 int k = 0; 1795 while (tmpc != NULL) 1796 { 1797 if (k == 0) 1798 { 1799 if (tmp_output == NULL) 1800 { 1801 tmp_output = (maps *) malloc (MAPS_SIZE); 1802 if (tmp_output == NULL) 1803 { 1804 return errorException (m, 1805 _ 1806 ("Unable to allocate memory."), 1807 "InternalError", NULL); 1808 } 1809 tmp_output->name = zStrdup (tmpc); 1810 tmp_output->content = NULL; 1811 tmp_output->next = NULL; 1812 } 1813 } 1814 else 1815 { 1816 char *tmpv = strstr (tmpc, "="); 1817 char tmpn[256]; 1818 memset (tmpn, 0, 256); 1819 strncpy (tmpn, tmpc, 1820 (strlen (tmpc) - 1821 strlen (tmpv)) * sizeof (char)); 1822 tmpn[strlen (tmpc) - strlen (tmpv)] = 0; 1823 #ifdef DEBUG 1824 fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn, 1825 tmpv + 1); 1826 #endif 1827 if (tmp_output->content == NULL) 1828 { 1829 tmp_output->content = createMap (tmpn, tmpv + 1); 1830 tmp_output->content->next = NULL; 1831 } 1832 else 1833 addToMap (tmp_output->content, tmpn, tmpv + 1); 1834 } 1835 k++; 1836 #ifdef DEBUG 1837 fprintf (stderr, "***%s***\n", tmpc); 1838 #endif 1839 tmpc = strtok (NULL, "@"); 1840 } 1841 if (request_output_real_format == NULL) 1842 request_output_real_format = dupMaps (&tmp_output); 1843 else 1844 addMapsToMaps (&request_output_real_format, tmp_output); 1845 freeMaps (&tmp_output); 1846 free (tmp_output); 1847 tmp_output = NULL; 1848 #ifdef DEBUG 1849 dumpMaps (tmp_output); 1850 fflush (stderr); 1851 #endif 1852 free (tmp); 1853 } 1854 free (outputs_as_text); 1855 } 1856 1857 1858 /** 1859 * Parsing inputs provided as KVP 1860 */ 1861 r_inputs = getMap (request_inputs, "DataInputs"); 1862 #ifdef DEBUG 1863 fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value); 1864 #endif 1865 char cursor_input[40960]; 1866 if (r_inputs != NULL){ 1867 snprintf (cursor_input, 40960, "%s", r_inputs->value); 1868 j = 0; 1869 1870 /** 1871 * Put each DataInputs into the inputs_as_text array 1872 */ 1873 char *tmp1 = zStrdup (cursor_input); 1874 char *pToken; 1875 pToken = strtok (cursor_input, ";"); 1876 if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0) 1877 { 1878 char *tmp2 = url_decode (tmp1); 1879 snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s", 1880 tmp2); 1881 free (tmp2); 1882 pToken = strtok (cursor_input, ";"); 1883 } 1884 free (tmp1); 1885 1886 char **inputs_as_text = (char **) malloc (100 * sizeof (char *)); 1887 if (inputs_as_text == NULL) 1888 { 1889 return errorException (m, _("Unable to allocate memory."), 1890 "InternalError", NULL); 1891 } 1892 i = 0; 1893 while (pToken != NULL) 1894 { 1895 #ifdef DEBUG 1896 fprintf (stderr, "***%s***\n", pToken); 1897 fflush (stderr); 1898 fprintf (stderr, "***%s***\n", pToken); 1899 #endif 1900 inputs_as_text[i] = 1901 (char *) malloc ((strlen (pToken) + 1) * sizeof (char)); 1902 if (inputs_as_text[i] == NULL) 1903 { 1904 return errorException (m, _("Unable to allocate memory."), 1905 "InternalError", NULL); 1906 } 1907 snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken); 1908 pToken = strtok (NULL, ";"); 1909 i++; 1910 } 1911 1912 for (j = 0; j < i; j++) 1913 { 1914 char *tmp = zStrdup (inputs_as_text[j]); 1915 free (inputs_as_text[j]); 1916 char *tmpc; 1917 tmpc = strtok (tmp, "@"); 1918 while (tmpc != NULL) 1919 { 1920 #ifdef DEBUG 1921 fprintf (stderr, "***\n***%s***\n", tmpc); 1922 #endif 1923 char *tmpv = strstr (tmpc, "="); 1924 char tmpn[256]; 1925 memset (tmpn, 0, 256); 1926 if (tmpv != NULL) 1927 { 1928 strncpy (tmpn, tmpc, 1929 (strlen (tmpc) - strlen (tmpv)) * sizeof (char)); 1930 tmpn[strlen (tmpc) - strlen (tmpv)] = 0; 1931 } 1932 else 1933 { 1934 strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char)); 1935 tmpn[strlen (tmpc)] = 0; 1936 } 1937 #ifdef DEBUG 1938 fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1); 1939 #endif 1940 if (tmpmaps == NULL) 1941 { 1942 tmpmaps = (maps *) malloc (MAPS_SIZE); 1943 if (tmpmaps == NULL) 1944 { 1945 return errorException (m, 1946 _("Unable to allocate memory."), 1947 "InternalError", NULL); 1948 } 1949 tmpmaps->name = zStrdup (tmpn); 1950 if (tmpv != NULL) 1951 { 1952 char *tmpvf = url_decode (tmpv + 1); 1953 tmpmaps->content = createMap ("value", tmpvf); 1954 free (tmpvf); 1955 } 1956 else 1957 tmpmaps->content = createMap ("value", "Reference"); 1958 tmpmaps->next = NULL; 1959 } 1960 tmpc = strtok (NULL, "@"); 1961 while (tmpc != NULL) 1962 { 1963 #ifdef DEBUG 1964 fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n", 1965 tmpc); 1966 #endif 1967 char *tmpv1 = strstr (tmpc, "="); 1968 #ifdef DEBUG 1969 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1970 tmpv1 + 1); 1971 #endif 1972 char tmpn1[1024]; 1973 memset (tmpn1, 0, 1024); 1974 if (tmpv1 != NULL) 1975 { 1976 strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1)); 1977 tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0; 1978 addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); 1979 } 1980 else 1981 { 1982 strncpy (tmpn1, tmpc, strlen (tmpc)); 1983 tmpn1[strlen (tmpc)] = 0; 1984 map *lmap = getLastMap (tmpmaps->content); 1985 char *tmpValue = 1986 (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) * 1987 sizeof (char)); 1988 sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc); 1989 free (lmap->value); 1990 lmap->value = zStrdup (tmpValue); 1991 free (tmpValue); 1992 tmpc = strtok (NULL, "@"); 1993 continue; 1994 } 1995 #ifdef DEBUG 1996 fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n", 1997 tmpn1); 1998 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1999 tmpv1 + 1); 2000 #endif 2001 if (strcmp (tmpn1, "xlink:href") != 0) 2002 addToMap (tmpmaps->content, tmpn1, tmpv1 + 1); 2003 else if (tmpv1 != NULL) 2004 { 2005 char *tmpx2 = url_decode (tmpv1 + 1); 2006 if (strncasecmp (tmpx2, "http://", 7) != 0 && 2007 strncasecmp (tmpx2, "ftp://", 6) != 0 && 2008 strncasecmp (tmpx2, "https://", 8) != 0) 2009 { 2010 char emsg[1024]; 2011 sprintf (emsg, 2012 _ 2013 ("Unable to find a valid protocol to download the remote file %s"), 2014 tmpv1 + 1); 2015 errorException (m, emsg, "InternalError", NULL); 2016 freeMaps (&m); 2017 free (m); 2018 free (REQUEST); 2019 free (SERVICE_URL); 2020 InternetCloseHandle (&hInternet); 2021 freeService (&s1); 2022 free (s1); 2023 return 0; 2024 } 2025 #ifdef DEBUG 2026 fprintf (stderr, 2027 "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n", 2028 tmpv1 + 1); 2029 #endif 2030 addToMap (tmpmaps->content, tmpn1, tmpx2); 2031 #ifndef WIN32 2032 if (CHECK_INET_HANDLE (hInternet)) 2033 #endif 2034 { 2035 if (loadRemoteFile 2036 (&m, &tmpmaps->content, &hInternet, tmpx2) < 0) 2037 { 2038 freeMaps (&m); 2039 free (m); 2040 free (REQUEST); 2041 free (SERVICE_URL); 2042 InternetCloseHandle (&hInternet); 2043 freeService (&s1); 2044 free (s1); 2045 return 0; 2046 } 2047 } 2048 free (tmpx2); 2049 addToMap (tmpmaps->content, "Reference", tmpv1 + 1); 2050 } 2051 tmpc = strtok (NULL, "@"); 2052 } 2053 #ifdef DEBUG 2054 dumpMaps (tmpmaps); 2055 fflush (stderr); 2056 #endif 2057 if (request_input_real_format == NULL) 2058 request_input_real_format = dupMaps (&tmpmaps); 2059 else 2060 { 2061 maps *testPresence = 2062 getMaps (request_input_real_format, tmpmaps->name); 2063 if (testPresence != NULL) 2064 { 2065 elements *elem = 2066 getElements (s1->inputs, tmpmaps->name); 2067 if (elem != NULL) 2068 { 2069 if (appendMapsToMaps 2070 (m, request_input_real_format, tmpmaps, 2071 elem) < 0) 2072 { 2073 freeMaps (&m); 2074 free (m); 2075 free (REQUEST); 2076 free (SERVICE_URL); 2077 InternetCloseHandle (&hInternet); 2078 freeService (&s1); 2079 free (s1); 2080 return 0; 2081 } 2082 } 2083 } 2084 else 2085 addMapsToMaps (&request_input_real_format, tmpmaps); 2086 } 2087 freeMaps (&tmpmaps); 2088 free (tmpmaps); 2089 tmpmaps = NULL; 2090 free (tmp); 2091 } 2092 } 2093 free (inputs_as_text); 2094 } 2095 } 2096 else 2097 { 2098 /** 2099 * Parse XML request 2100 */ 2101 xmlInitParser (); 2102 #ifdef DEBUG 2103 fflush (stderr); 2104 fprintf (stderr, "BEFORE %s\n", postRequest->value); 2105 fflush (stderr); 2106 #endif 2107 xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength); 2108 #ifdef DEBUG 2109 fprintf (stderr, "AFTER\n"); 2110 fflush (stderr); 2111 #endif 2112 2113 /** 2114 * Parse every Input in DataInputs node. 2115 */ 2116 xmlXPathObjectPtr tmpsptr = 2117 extractFromDoc (doc, "/*/*/*[local-name()='Input']"); 2118 xmlNodeSet *tmps = tmpsptr->nodesetval; 2119 #ifdef DEBUG 2120 fprintf (stderr, "*****%d*****\n", tmps->nodeNr); 2121 #endif 2122 for (int k = 0; k < tmps->nodeNr; k++) 2123 { 2124 maps *tmpmaps = NULL; 2125 xmlNodePtr cur = tmps->nodeTab[k]; 2126 if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE) 2127 { 2128 /** 2129 * A specific Input node. 2130 */ 2131 #ifdef DEBUG 2132 fprintf (stderr, "= element 0 node \"%s\"\n", cur->name); 2133 #endif 2134 xmlNodePtr cur2 = cur->children; 2135 while (cur2 != NULL) 2136 { 2137 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2138 cur2 = cur2->next; 2139 if (cur2 == NULL) 2140 break; 2141 /** 2142 * Indentifier 2143 */ 2144 if (xmlStrncasecmp 2145 (cur2->name, BAD_CAST "Identifier", 2146 xmlStrlen (cur2->name)) == 0) 2147 { 2148 xmlChar *val = 2149 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 2150 if (tmpmaps == NULL) 2151 { 2152 tmpmaps = (maps *) malloc (MAPS_SIZE); 2153 if (tmpmaps == NULL) 2154 { 2155 return errorException (m, 2156 _ 2157 ("Unable to allocate memory."), 2158 "InternalError", NULL); 2159 } 2160 tmpmaps->name = zStrdup ((char *) val); 2161 tmpmaps->content = NULL; 2162 tmpmaps->next = NULL; 2163 } 2164 xmlFree (val); 2165 } 2166 /** 2167 * Title, Asbtract 2168 */ 2169 if (xmlStrncasecmp 2170 (cur2->name, BAD_CAST "Title", 2171 xmlStrlen (cur2->name)) == 0 2172 || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract", 2173 xmlStrlen (cur2->name)) == 0) 2174 { 2175 xmlChar *val = 2176 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 2177 if (tmpmaps == NULL) 2178 { 2179 tmpmaps = (maps *) malloc (MAPS_SIZE); 2180 if (tmpmaps == NULL) 2181 { 2182 return errorException (m, 2183 _ 2184 ("Unable to allocate memory."), 2185 "InternalError", NULL); 2186 } 2187 tmpmaps->name = zStrdup ("missingIndetifier"); 2188 tmpmaps->content = 2189 createMap ((char *) cur2->name, (char *) val); 2190 tmpmaps->next = NULL; 2191 } 2192 else 2193 { 2194 if (tmpmaps->content != NULL) 2195 addToMap (tmpmaps->content, 2196 (char *) cur2->name, (char *) val); 2197 else 2198 tmpmaps->content = 2199 createMap ((char *) cur2->name, (char *) val); 2200 } 2201 #ifdef DEBUG 2202 dumpMaps (tmpmaps); 2203 #endif 2204 xmlFree (val); 2205 } 2206 /** 2207 * InputDataFormChoice (Reference or Data ?) 2208 */ 2209 if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0) 2210 { 2211 /** 2212 * Get every attribute from a Reference node 2213 * mimeType, encoding, schema, href, method 2214 * Header and Body gesture should be added here 2215 */ 2216 #ifdef DEBUG 2217 fprintf (stderr, "REFERENCE\n"); 2218 #endif 2219 const char *refs[5] = 2220 { "mimeType", "encoding", "schema", "method", 2221 "href" 2222 }; 2223 for (int l = 0; l < 5; l++) 2224 { 2225 #ifdef DEBUG 2226 fprintf (stderr, "*** %s ***", refs[l]); 2227 #endif 2228 xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]); 2229 if (val != NULL && xmlStrlen (val) > 0) 2230 { 2231 if (tmpmaps->content != NULL) 2232 addToMap (tmpmaps->content, refs[l], 2233 (char *) val); 2234 else 2235 tmpmaps->content = 2236 createMap (refs[l], (char *) val); 2237 map *ltmp = getMap (tmpmaps->content, "method"); 2238 if (l == 4) 2239 { 2240 if (! 2241 (ltmp != NULL 2242 && strncmp (ltmp->value, "POST", 2243 4) == 0) 2244 && CHECK_INET_HANDLE (hInternet)) 2245 { 2246 if (loadRemoteFile 2247 (&m, &tmpmaps->content, &hInternet, 2248 (char *) val) != 0) 2249 { 2250 freeMaps (&m); 2251 free (m); 2252 free (REQUEST); 2253 free (SERVICE_URL); 2254 InternetCloseHandle (&hInternet); 2255 freeService (&s1); 2256 free (s1); 2257 return 0; 2258 } 2259 } 2260 } 2261 } 2262 #ifdef DEBUG 2263 fprintf (stderr, "%s\n", val); 2264 #endif 2265 xmlFree (val); 2266 } 2267 #ifdef POST_DEBUG 2268 fprintf (stderr, 2269 "Parse Header and Body from Reference \n"); 2270 #endif 2271 xmlNodePtr cur3 = cur2->children; 2272 /* HINTERNET hInternetP; 2273 hInternetP=InternetOpen( 2274 #ifndef WIN32 2275 (LPCTSTR) 2276 #endif 2277 "ZooWPSClient\0", 2278 INTERNET_OPEN_TYPE_PRECONFIG, 2279 NULL,NULL, 0); */ 2280 //hInternet.ihandle[hInternet.nb].header=NULL; 2281 while (cur3 != NULL) 2282 { 2283 while (cur3 != NULL 2284 && cur3->type != XML_ELEMENT_NODE) 2285 cur3 = cur3->next; 2286 if (cur3 == NULL) 2287 break; 2288 if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") == 2289 0) 2290 { 2291 const char *ha[2]; 2292 ha[0] = "key"; 2293 ha[1] = "value"; 2294 int hai; 2295 char *has; 2296 char *key; 2297 for (hai = 0; hai < 2; hai++) 2298 { 2299 xmlChar *val = 2300 xmlGetProp (cur3, BAD_CAST ha[hai]); 2301 #ifdef POST_DEBUG 2302 fprintf (stderr, "%s = %s\n", ha[hai], 2303 (char *) val); 2304 #endif 2305 if (hai == 0) 2306 { 2307 key = zStrdup ((char *) val); 2308 } 2309 else 2310 { 2311 has = 2312 (char *) 2313 malloc ((4 + xmlStrlen (val) + 2314 strlen (key)) * 2315 sizeof (char)); 2316 if (has == NULL) 2317 { 2318 return errorException (m, 2319 _ 2320 ("Unable to allocate memory."), 2321 "InternalError", 2322 NULL); 2323 } 2324 snprintf (has, 2325 (3 + xmlStrlen (val) + 2326 strlen (key)), "%s: %s", key, 2327 (char *) val); 2328 free (key); 2329 #ifdef POST_DEBUG 2330 fprintf (stderr, "%s\n", has); 2331 #endif 2332 } 2333 xmlFree (val); 2334 } 2335 hInternet.ihandle[hInternet.nb].header = 2336 curl_slist_append (hInternet.ihandle 2337 [hInternet.nb].header, 2338 has); 2339 if (has != NULL) 2340 free (has); 2341 } 2342 else 2343 { 2344 #ifdef POST_DEBUG 2345 fprintf (stderr, 2346 "Try to fetch the body part of the request ...\n"); 2347 #endif 2348 if (xmlStrcasecmp (cur3->name, BAD_CAST "Body") 2349 == 0) 2350 { 2351 #ifdef POST_DEBUG 2352 fprintf (stderr, "Body part found !!!\n", 2353 (char *) cur3->content); 2354 #endif 2355 char *tmp = 2356 (char *) malloc (cgiContentLength + 2357 1 * sizeof (char)); 2358 memset (tmp, 0, cgiContentLength); 2359 xmlNodePtr cur4 = cur3->children; 2360 while (cur4 != NULL) 2361 { 2362 while (cur4->type != XML_ELEMENT_NODE) 2363 cur4 = cur4->next; 2364 xmlDocPtr bdoc = 2365 xmlNewDoc (BAD_CAST "1.0"); 2366 bdoc->encoding = 2367 xmlCharStrdup ("UTF-8"); 2368 xmlDocSetRootElement (bdoc, cur4); 2369 xmlChar *btmps; 2370 int bsize; 2371 xmlDocDumpMemory (bdoc, &btmps, &bsize); 2372 #ifdef POST_DEBUG 2373 fprintf (stderr, 2374 "Body part found !!! %s %s\n", 2375 tmp, (char *) btmps); 2376 #endif 2377 if (btmps != NULL) 2378 sprintf (tmp, "%s", (char *) btmps); 2379 xmlFree (btmps); 2380 cur4 = cur4->next; 2381 xmlFreeDoc (bdoc); 2382 } 2383 map *btmp = 2384 getMap (tmpmaps->content, "href"); 2385 if (btmp != NULL) 2386 { 2387 #ifdef POST_DEBUG 2388 fprintf (stderr, "%s %s\n", btmp->value, 2389 tmp); 2390 curl_easy_setopt (hInternet.handle, 2391 CURLOPT_VERBOSE, 1); 2392 #endif 2393 hInternet. 2394 waitingRequests[hInternet.nb] = 2395 strdup (tmp); 2396 InternetOpenUrl (&hInternet, 2397 btmp->value, 2398 hInternet.waitingRequests 2399 [hInternet.nb], 2400 strlen 2401 (hInternet.waitingRequests 2402 [hInternet.nb]), 2403 INTERNET_FLAG_NO_CACHE_WRITE, 2404 0); 2405 } 2406 free (tmp); 2407 } 2408 else 2409 if (xmlStrcasecmp 2410 (cur3->name, 2411 BAD_CAST "BodyReference") == 0) 2412 { 2413 xmlChar *val = 2414 xmlGetProp (cur3, BAD_CAST "href"); 2415 HINTERNET bInternet, res1; 2416 bInternet = InternetOpen ( 2417 #ifndef WIN32 2418 (LPCTSTR) 2419 #endif 2420 "ZooWPSClient\0", 2421 INTERNET_OPEN_TYPE_PRECONFIG, 2422 NULL, NULL, 0); 2423 if (!CHECK_INET_HANDLE (hInternet)) 2424 fprintf (stderr, 2425 "WARNING : hInternet handle failed to initialize"); 2426 #ifdef POST_DEBUG 2427 curl_easy_setopt (bInternet.handle, 2428 CURLOPT_VERBOSE, 1); 2429 #endif 2430 bInternet.waitingRequests[0] = 2431 strdup ((char *) val); 2432 res1 = 2433 InternetOpenUrl (&bInternet, 2434 bInternet.waitingRequests 2435 [0], NULL, 0, 2436 INTERNET_FLAG_NO_CACHE_WRITE, 2437 0); 2438 processDownloads (&bInternet); 2439 char *tmp = 2440 (char *) 2441 malloc ((bInternet.ihandle[0].nDataLen + 2442 1) * sizeof (char)); 2443 if (tmp == NULL) 2444 { 2445 return errorException (m, 2446 _ 2447 ("Unable to allocate memory."), 2448 "InternalError", 2449 NULL); 2450 } 2451 size_t bRead; 2452 InternetReadFile (bInternet.ihandle[0], 2453 (LPVOID) tmp, 2454 bInternet. 2455 ihandle[0].nDataLen, 2456 &bRead); 2457 tmp[bInternet.ihandle[0].nDataLen] = 0; 2458 InternetCloseHandle (&bInternet); 2459 map *btmp = 2460 getMap (tmpmaps->content, "href"); 2461 if (btmp != NULL) 2462 { 2463 #ifdef POST_DEBUG 2464 fprintf (stderr, "%s %s\n", btmp->value, 2465 tmp); 2466 #endif 2467 hInternet. 2468 waitingRequests[hInternet.nb] = 2469 strdup (tmp); 2470 res = 2471 InternetOpenUrl (&hInternet, 2472 btmp->value, 2473 hInternet.waitingRequests 2474 [hInternet.nb], 2475 strlen 2476 (hInternet.waitingRequests 2477 [hInternet.nb]), 2478 INTERNET_FLAG_NO_CACHE_WRITE, 2479 0); 2480 } 2481 free (tmp); 2482 } 2483 } 2484 cur3 = cur3->next; 2485 } 2486 #ifdef POST_DEBUG 2487 fprintf (stderr, 2488 "Header and Body was parsed from Reference \n"); 2489 #endif 2490 #ifdef DEBUG 2491 dumpMap (tmpmaps->content); 2492 fprintf (stderr, "= element 2 node \"%s\" = (%s)\n", 2493 cur2->name, cur2->content); 2494 #endif 2495 } 2496 else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0) 2497 { 2498 #ifdef DEBUG 2499 fprintf (stderr, "DATA\n"); 2500 #endif 2501 xmlNodePtr cur4 = cur2->children; 2502 while (cur4 != NULL) 2503 { 2504 while (cur4 != NULL 2505 && cur4->type != XML_ELEMENT_NODE) 2506 cur4 = cur4->next; 2507 if (cur4 == NULL) 2508 break; 2509 if (xmlStrcasecmp 2510 (cur4->name, BAD_CAST "LiteralData") == 0) 2511 { 2512 /** 2513 * Get every attribute from a LiteralData node 2514 * dataType , uom 2515 */ 2516 char *list[2]; 2517 list[0] = zStrdup ("dataType"); 2518 list[1] = zStrdup ("uom"); 2519 for (int l = 0; l < 2; l++) 2520 { 2521 #ifdef DEBUG 2522 fprintf (stderr, "*** LiteralData %s ***", 2523 list[l]); 2524 #endif 2525 xmlChar *val = 2526 xmlGetProp (cur4, BAD_CAST list[l]); 2527 if (val != NULL 2528 && strlen ((char *) val) > 0) 2529 { 2530 if (tmpmaps->content != NULL) 2531 addToMap (tmpmaps->content, list[l], 2532 (char *) val); 2533 else 2534 tmpmaps->content = 2535 createMap (list[l], (char *) val); 2536 #ifdef DEBUG 2537 fprintf (stderr, "%s\n", val); 2538 #endif 2539 } 2540 xmlFree (val); 2541 free (list[l]); 2542 } 2543 } 2544 else 2545 if (xmlStrcasecmp 2546 (cur4->name, BAD_CAST "ComplexData") == 0) 2547 { 2548 /** 2549 * Get every attribute from a Reference node 2550 * mimeType, encoding, schema 2551 */ 2552 const char *coms[3] = 2553 { "mimeType", "encoding", "schema" }; 2554 for (int l = 0; l < 3; l++) 2555 { 2556 #ifdef DEBUG 2557 fprintf (stderr, "*** ComplexData %s ***\n", 2558 coms[l]); 2559 #endif 2560 xmlChar *val = 2561 xmlGetProp (cur4, BAD_CAST coms[l]); 2562 if (val != NULL 2563 && strlen ((char *) val) > 0) 2564 { 2565 if (tmpmaps->content != NULL) 2566 addToMap (tmpmaps->content, coms[l], 2567 (char *) val); 2568 else 2569 tmpmaps->content = 2570 createMap (coms[l], (char *) val); 2571 #ifdef DEBUG 2572 fprintf (stderr, "%s\n", val); 2573 #endif 2574 } 2575 xmlFree (val); 2576 } 2577 } 2578 2579 map *test = getMap (tmpmaps->content, "encoding"); 2580 2581 if (test == NULL) 2582 { 2583 if (tmpmaps->content != NULL) 2584 addToMap (tmpmaps->content, "encoding", 2585 "utf-8"); 2586 else 2587 tmpmaps->content = 2588 createMap ("encoding", "utf-8"); 2589 test = getMap (tmpmaps->content, "encoding"); 2590 } 2591 2592 if (strcasecmp (test->value, "base64") != 0) 2593 { 2594 xmlChar *mv = xmlNodeListGetString (doc, 2595 cur4-> 2596 xmlChildrenNode, 2597 1); 2598 map *ltmp = 2599 getMap (tmpmaps->content, "mimeType"); 2600 if (mv == NULL 2601 || 2602 (xmlStrcasecmp 2603 (cur4->name, BAD_CAST "ComplexData") == 0 2604 && (ltmp == NULL 2605 || strncasecmp (ltmp->value, 2606 "text/xml", 8) == 0))) 2607 { 2608 xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); 2609 int buffersize; 2610 xmlNodePtr cur5 = cur4->children; 2611 while (cur5 != NULL 2612 && cur5->type != XML_ELEMENT_NODE 2613 && cur5->type != 2614 XML_CDATA_SECTION_NODE) 2615 cur5 = cur5->next; 2616 if (cur5 != NULL 2617 && cur5->type != XML_CDATA_SECTION_NODE) 2618 { 2619 xmlDocSetRootElement (doc1, cur5); 2620 xmlDocDumpFormatMemoryEnc (doc1, &mv, 2621 &buffersize, 2622 "utf-8", 1); 2623 char size[1024]; 2624 sprintf (size, "%d", buffersize); 2625 addToMap (tmpmaps->content, "size", 2626 size); 2627 xmlFreeDoc (doc1); 2628 } 2629 else 2630 { 2631 if (cur5 != NULL 2632 && cur5->type == XML_CDATA_SECTION_NODE){ 2633 xmlDocPtr doc2 = xmlParseMemory((const char*)cur5->content,xmlStrlen(cur5->content)); 2634 xmlDocSetRootElement (doc1,xmlDocGetRootElement(doc2)); 2635 xmlDocDumpFormatMemoryEnc (doc1, &mv, 2636 &buffersize, 2637 "utf-8", 1); 2638 char size[1024]; 2639 sprintf (size, "%d", buffersize); 2640 addToMap (tmpmaps->content, "size", 2641 size); 2642 xmlFreeDoc (doc2); 2643 xmlFreeDoc (doc1); 2644 } 2645 } 2646 }else{ 2647 xmlNodePtr cur5 = cur4->children; 2648 while (cur5 != NULL 2649 && cur5->type != XML_CDATA_SECTION_NODE) 2650 cur5 = cur5->next; 2651 if (cur5 != NULL 2652 && cur5->type == XML_CDATA_SECTION_NODE){ 2653 xmlFree(mv); 2654 mv=xmlStrdup(cur5->content); 2655 } 2656 } 2657 if (mv != NULL) 2658 { 2659 addToMap (tmpmaps->content, "value", 2660 (char *) mv); 2661 xmlFree (mv); 2662 } 2663 } 2664 else 2665 { 2666 xmlChar *tmp = xmlNodeListGetRawString (doc, 2667 cur4->xmlChildrenNode, 2668 0); 2669 addToMap (tmpmaps->content, "value", 2670 (char *) tmp); 2671 map *tmpv = getMap (tmpmaps->content, "value"); 2672 char *res = NULL; 2673 char *curs = tmpv->value; 2674 for (int i = 0; i <= strlen (tmpv->value) / 64; 2675 i++) 2676 { 2677 if (res == NULL) 2678 res = 2679 (char *) malloc (67 * sizeof (char)); 2680 else 2681 res = 2682 (char *) realloc (res, 2683 (((i + 1) * 65) + 2684 i) * sizeof (char)); 2685 int csize = i * 65; 2686 strncpy (res + csize, curs, 64); 2687 if (i == xmlStrlen (tmp) / 64) 2688 strcat (res, "\n\0"); 2689 else 2690 { 2691 strncpy (res + (((i + 1) * 64) + i), 2692 "\n\0", 2); 2693 curs += 64; 2694 } 2695 } 2696 free (tmpv->value); 2697 tmpv->value = zStrdup (res); 2698 free (res); 2699 xmlFree (tmp); 2700 } 2701 cur4 = cur4->next; 2702 } 2703 } 2704 #ifdef DEBUG 2705 fprintf (stderr, "cur2 next \n"); 2706 fflush (stderr); 2707 #endif 2708 cur2 = cur2->next; 2709 } 2710 #ifdef DEBUG 2711 fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n"); 2712 fflush (stderr); 2713 #endif 2714 2715 { 2716 maps *testPresence = 2717 getMaps (request_input_real_format, tmpmaps->name); 2718 if (testPresence != NULL) 2719 { 2720 elements *elem = getElements (s1->inputs, tmpmaps->name); 2721 if (elem != NULL) 2722 { 2723 if (appendMapsToMaps 2724 (m, request_input_real_format, tmpmaps, elem) < 0) 2725 { 2726 freeMaps (&m); 2727 free (m); 2728 free (REQUEST); 2729 free (SERVICE_URL); 2730 InternetCloseHandle (&hInternet); 2731 freeService (&s1); 2732 free (s1); 2733 return 0; 2734 } 2735 } 2736 } 2737 else 2738 addMapsToMaps (&request_input_real_format, tmpmaps); 2739 } 2740 2741 #ifdef DEBUG 2742 fprintf (stderr, "******TMPMAPS*****\n"); 2743 dumpMaps (tmpmaps); 2744 fprintf (stderr, "******REQUESTMAPS*****\n"); 2745 dumpMaps (request_input_real_format); 2746 #endif 2747 freeMaps (&tmpmaps); 2748 free (tmpmaps); 2749 tmpmaps = NULL; 2750 } 2751 #ifdef DEBUG 2752 dumpMaps (tmpmaps); 2753 #endif 2754 } 2755 #ifdef DEBUG 2756 fprintf (stderr, "Search for response document node\n"); 2757 #endif 2758 xmlXPathFreeObject (tmpsptr); 2759 2760 tmpsptr = 2761 extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); 2762 bool asRaw = false; 2763 tmps = tmpsptr->nodesetval; 2764 if (tmps->nodeNr == 0) 2765 { 2766 xmlXPathFreeObject (tmpsptr); 2767 tmpsptr = 2768 extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); 2769 tmps = tmpsptr->nodesetval; 2770 asRaw = true; 2771 } 2772 #ifdef DEBUG 2773 fprintf (stderr, "*****%d*****\n", tmps->nodeNr); 2774 #endif 2775 if (asRaw == true) 2776 { 2777 addToMap (request_inputs, "RawDataOutput", ""); 2778 xmlNodePtr cur0 = tmps->nodeTab[0]; 2779 if (cur0->type == XML_ELEMENT_NODE) 2780 { 2781 2782 maps *tmpmaps = (maps *) malloc (MAPS_SIZE); 2783 if (tmpmaps == NULL) 2784 { 2785 return errorException (m, _("Unable to allocate memory."), 2786 "InternalError", NULL); 2787 } 2788 tmpmaps->name = zStrdup ("unknownIdentifier"); 2789 tmpmaps->content = NULL; 2790 tmpmaps->next = NULL; 2791 2792 /** 2793 * Get every attribute from a RawDataOutput node 2794 * mimeType, encoding, schema, uom 2795 */ 2796 const char *outs[4] = 2797 { "mimeType", "encoding", "schema", "uom" }; 2798 for (int l = 0; l < 4; l++) 2799 { 2800 #ifdef DEBUG 2801 fprintf (stderr, "*** %s ***\t", outs[l]); 2802 #endif 2803 xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]); 2804 if (val != NULL) 2805 { 2806 if (strlen ((char *) val) > 0) 2807 { 2808 if (tmpmaps->content != NULL) 2809 addToMap (tmpmaps->content, outs[l], 2810 (char *) val); 2811 else 2812 tmpmaps->content = 2813 createMap (outs[l], (char *) val); 2814 } 2815 xmlFree (val); 2816 } 2817 } 2818 xmlNodePtr cur2 = cur0->children; 2819 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2820 cur2 = cur2->next; 2821 while (cur2 != NULL) 2822 { 2823 if (xmlStrncasecmp 2824 (cur2->name, BAD_CAST "Identifier", 2825 xmlStrlen (cur2->name)) == 0) 2826 { 2827 xmlChar *val = 2828 xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1); 2829 free (tmpmaps->name); 2830 tmpmaps->name = zStrdup ((char *) val); 2831 xmlFree (val); 2832 } 2833 cur2 = cur2->next; 2834 while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE) 2835 cur2 = cur2->next; 2836 } 2837 if (request_output_real_format == NULL) 2838 request_output_real_format = dupMaps (&tmpmaps); 2839 else 2840 addMapsToMaps (&request_output_real_format, tmpmaps); 2841 if (tmpmaps != NULL) 2842 { 2843 freeMaps (&tmpmaps); 2844 free (tmpmaps); 2845 tmpmaps = NULL; 2846 } 2847 } 2848 } 2849 else 2850 { 2851 addToMap (request_inputs, "ResponseDocument", ""); 2852 2853 xmlNodePtr cur = tmps->nodeTab[0]; // only one ResponseDocument node 2854 if (cur->type == XML_ELEMENT_NODE) { 2855 /** 2856 * Get every attribute: storeExecuteResponse, lineage, status 2857 */ 2858 //map* attributes = NULL; 2859 const char *ress[3] = 2860 { "storeExecuteResponse", "lineage", "status" }; 2861 xmlChar *val; 2862 for (int l = 0; l < 3; l++) 2863 { 2864 #ifdef DEBUG 2865 fprintf (stderr, "*** %s ***\t", ress[l]); 2866 #endif 2867 val = xmlGetProp (cur, BAD_CAST ress[l]); 2868 if (val != NULL && strlen ((char *) val) > 0) 2869 { 2870 /* 2871 if (attributes == NULL) { 2872 attributes = createMap (ress[l], (char *) val); 2873 } 2874 else { 2875 addToMap (attributes, ress[l], (char *) val); 2876 } 2877 */ 2878 addToMap (request_inputs, ress[l], (char *) val); 2879 } 2880 #ifdef DEBUG 2881 fprintf (stderr, "%s\n", val); 2882 #endif 2883 xmlFree (val); 2884 } 2885 2886 xmlNodePtr cur1 = cur->children; 2887 while (cur1 != NULL) // iterate over Output nodes 2888 { 2889 if (cur1->type != XML_ELEMENT_NODE || 2890 xmlStrncasecmp(cur1->name, BAD_CAST "Output", 2891 xmlStrlen (cur1->name)) != 0) { 2892 cur1 = cur1->next; 2893 continue; 2894 } 2895 2896 maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node 2897 if (tmpmaps == NULL) { 2898 return errorException (m, 2899 _ 2900 ("Unable to allocate memory."), 2901 "InternalError", NULL); 2902 } 2903 tmpmaps->name = zStrdup ("unknownIdentifier"); 2904 tmpmaps->content = NULL; 2905 tmpmaps->next = NULL; 2906 2907 xmlNodePtr elems = cur1->children; 2908 2909 while (elems != NULL) { 2910 2911 /** 2912 * Identifier 2913 */ 2914 if (xmlStrncasecmp 2915 (elems->name, BAD_CAST "Identifier", 2916 xmlStrlen (elems->name)) == 0) 2917 { 2918 xmlChar *val = 2919 xmlNodeListGetString (doc, elems->xmlChildrenNode, 1); 2920 2921 free(tmpmaps->name); 2922 tmpmaps->name = zStrdup ((char *) val); 2923 if (tmpmaps->content == NULL) { 2924 tmpmaps->content = createMap("Identifier", zStrdup ((char *) val)); 2925 } 2926 else { 2927 addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val)); 2928 } 2929 2930 map* tt = getMap (request_inputs, "ResponseDocument"); 2931 if (strlen(tt->value) == 0) { 2932 addToMap (request_inputs, "ResponseDocument", 2933 (char *) val); 2934 } 2935 else { 2936 char* tmp = (char*) malloc((strlen(tt->value) + 1 2937 + strlen((char*) val) + 1) * sizeof(char)); 2938 sprintf (tmp, "%s;%s", tt->value, (char *) val); 2939 free(tt->value); 2940 tt->value = tmp; 2941 } 2942 xmlFree (val); 2943 } 2944 /** 2945 * Title, Abstract 2946 */ 2947 else if (xmlStrncasecmp(elems->name, BAD_CAST "Title", 2948 xmlStrlen (elems->name)) == 0 2949 || xmlStrncasecmp(elems->name, BAD_CAST "Abstract", 2950 xmlStrlen (elems->name)) == 0) 2951 { 2952 xmlChar *val = 2953 xmlNodeListGetString (doc, elems->xmlChildrenNode, 1); 2954 2955 if (tmpmaps->content == NULL) { 2956 tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val)); 2957 } 2958 else { 2959 addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val)); 2960 } 2961 xmlFree (val); 2962 } 2963 elems = elems->next; 2964 } 2965 2966 /** 2967 * Get every attribute from an Output node: 2968 * mimeType, encoding, schema, uom, asReference 2969 */ 2970 const char *outs[5] = 2971 { "mimeType", "encoding", "schema", "uom", "asReference" }; 2972 2973 for (int l = 0; l < 5; l++) { 2974 #ifdef DEBUG 2975 fprintf (stderr, "*** %s ***\t", outs[l]); 2976 #endif 2977 xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]); 2978 if (val != NULL && xmlStrlen(val) > 0) { 2979 if (tmpmaps->content != NULL) { 2980 addToMap (tmpmaps->content, outs[l], (char *) val); 2981 } 2982 else { 2983 tmpmaps->content = createMap (outs[l], (char *) val); 2984 } 2985 } 2986 #ifdef DEBUG 2987 fprintf (stderr, "%s\n", val); 2988 #endif 2989 xmlFree (val); 2990 } 2991 2992 if (request_output_real_format == NULL) { 2993 request_output_real_format = tmpmaps; 2994 } 2995 else if (getMaps(request_output_real_format, tmpmaps->name) != NULL) { 2996 return errorException (m, 2997 _ 2998 ("Duplicate <Output> elements in WPS Execute request"), 2999 "InternalError", NULL); 3000 } 3001 else { 3002 maps* mptr = request_output_real_format; 3003 while (mptr->next != NULL) { 3004 mptr = mptr->next; 3005 } 3006 mptr->next = tmpmaps; 3007 } 3008 cur1 = cur1->next; 3009 } 3010 } 3011 } 3012 xmlXPathFreeObject (tmpsptr); 3013 xmlFreeDoc (doc); 3014 xmlCleanupParser (); 3015 } 3016 3017 runHttpRequests (&m, &request_input_real_format, &hInternet); 3018 3019 // if(CHECK_INET_HANDLE(hInternet)) 3020 InternetCloseHandle (&hInternet); 3021 3022 #ifdef DEBUG 3023 fprintf (stderr, "\n%d\n", __LINE__); 3024 fflush (stderr); 3025 dumpMaps (request_input_real_format); 3026 dumpMaps (request_output_real_format); 3027 dumpMap (request_inputs); 3028 fprintf (stderr, "\n%d\n", __LINE__); 3029 fflush (stderr); 3030 #endif 3031 3032 /** 3033 * Ensure that each requested arguments are present in the request 3034 * DataInputs and ResponseDocument / RawDataOutput 3035 */ 3036 map* errI=NULL; 3037 #ifdef DEBUG 3038 dumpMaps(request_input_real_format); 3039 #endif 3040 char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI); 3041 #ifdef DEBUG 3042 dumpMaps(request_input_real_format); 3043 #endif 3044 maps *ptr = request_input_real_format; 3045 while (ptr != NULL) 3046 { 3047 map *tmp0 = getMap (ptr->content, "size"); 3048 map *tmp1 = getMap (ptr->content, "maximumMegabytes"); 3049 if (tmp1 != NULL && tmp0 != NULL) 3050 { 3051 float i = atof (tmp0->value) / 1048576.0; 3052 if (i >= atoi (tmp1->value)) 3053 { 3054 char tmps[1024]; 3055 map *tmpe = createMap ("code", "FileSizeExceeded"); 3056 snprintf (tmps, 1024, 3057 _ 3058 ("The <%s> parameter has a size limit (%s MB) defined in the ZOO ServicesProvider configuration file, but the reference you provided exceeds this limit (%f MB)."), 3059 ptr->name, tmp1->value, i); 3060 addToMap (tmpe, "locator", ptr->name); 3061 addToMap (tmpe, "text", tmps); 3062 printExceptionReportResponse (m, tmpe); 3063 freeService (&s1); 3064 free (s1); 3065 freeMap (&tmpe); 3066 free (tmpe); 3067 freeMaps (&m); 3068 free (m); 3069 free (REQUEST); 3070 free (SERVICE_URL); 3071 freeMaps (&request_input_real_format); 3072 free (request_input_real_format); 3073 freeMaps (&request_output_real_format); 3074 free (request_output_real_format); 3075 freeMaps (&tmpmaps); 3076 free (tmpmaps); 3077 return 1; 3078 } 3079 } 3080 ptr = ptr->next; 3081 } 3082 3083 map* errO=NULL; 3084 char *dfv1 = 3085 addDefaultValues (&request_output_real_format, s1->outputs, m, 1,&errO); 3086 if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0) 3087 { 3088 char tmps[1024]; 3089 map *tmpe = NULL; 3090 if (strcmp (dfv, "") != 0) 3091 { 3092 tmpe = createMap ("code", "MissingParameterValue"); 3093 int nb=0; 3094 int length=1; 3095 map* len=getMap(errI,"length"); 3096 if(len!=NULL) 3097 length=atoi(len->value); 3098 for(nb=0;nb<length;nb++){ 3099 map* errp=getMapArray(errI,"value",nb); 3100 snprintf (tmps, 1024, 3101 _ 3102 ("The <%s> argument was not specified in DataInputs but is required according to the ZOO ServicesProvider configuration file."), 3103 errp->value); 3104 setMapArray (tmpe, "locator", nb , errp->value); 3105 setMapArray (tmpe, "text", nb , tmps); 3106 setMapArray (tmpe, "code", nb , "MissingParameterValue"); 3107 } 3108 } 3109 if (strcmp (dfv1, "") != 0) 3110 { 3111 int ilength=0; 3112 if(tmpe==NULL) 3113 tmpe = createMap ("code", "InvalidParameterValue"); 3114 else{ 3115 map* len=getMap(tmpe,"length"); 3116 if(len!=NULL) 3117 ilength=atoi(len->value); 3118 } 3119 int nb=0; 3120 int length=1; 3121 map* len=getMap(errO,"length"); 3122 if(len!=NULL) 3123 length=atoi(len->value); 3124 for(nb=0;nb<length;nb++){ 3125 map* errp=getMapArray(errO,"value",nb); 3126 snprintf (tmps, 1024, 3127 _ 3128 ("The <%s> argument specified as %s identifier was not recognized (not defined in the ZOO Configuration File)."), 3129 errp->value, 3130 ((getMap(request_inputs,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument")); 3131 setMapArray (tmpe, "locator", nb+ilength , errp->value); 3132 setMapArray (tmpe, "text", nb+ilength , tmps); 3133 setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue"); 3134 } 3135 } 3136 printExceptionReportResponse (m, tmpe); 3137 freeService (&s1); 3138 free (s1); 3139 freeMap (&tmpe); 3140 free (tmpe); 3141 freeMaps (&m); 3142 free (m); 3143 free (REQUEST); 3144 free (SERVICE_URL); 3145 freeMaps (&request_input_real_format); 3146 free (request_input_real_format); 3147 freeMaps (&request_output_real_format); 3148 free (request_output_real_format); 3149 freeMaps (&tmpmaps); 3150 free (tmpmaps); 3151 if(errI!=NULL){ 3152 freeMap(&errI); 3153 free(errI); 3154 } 3155 if(errO!=NULL){ 3156 freeMap(&errO); 3157 free(errO); 3158 } 3159 return 1; 3160 } 3161 maps *tmpReqI = request_input_real_format; 3162 while (tmpReqI != NULL) 3163 { 3164 char name[1024]; 3165 if (getMap (tmpReqI->content, "isFile") != NULL) 3166 { 3167 if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) == 3168 cgiFormSuccess) 3169 { 3170 int BufferLen = 1024; 3171 cgiFilePtr file; 3172 int targetFile; 3173 char storageNameOnServer[2048]; 3174 char fileNameOnServer[64]; 3175 char contentType[1024]; 3176 char buffer[1024]; 3177 char *tmpStr = NULL; 3178 int size; 3179 int got, t; 3180 map *path = getMapFromMaps (m, "main", "tmpPath"); 3181 cgiFormFileSize (tmpReqI->name, &size); 3182 cgiFormFileContentType (tmpReqI->name, contentType, 3183 sizeof (contentType)); 3184 if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess) 3185 { 3186 t = -1; 3187 while (1) 3188 { 3189 tmpStr = strstr (name + t + 1, "\\"); 3190 if (NULL == tmpStr) 3191 tmpStr = strstr (name + t + 1, "/"); 3192 if (NULL != tmpStr) 3193 t = (int) (tmpStr - name); 3194 else 3195 break; 3196 } 3197 strcpy (fileNameOnServer, name + t + 1); 3198 3199 sprintf (storageNameOnServer, "%s/%s", path->value, 3200 fileNameOnServer); 3201 #ifdef DEBUG 3202 fprintf (stderr, "Name on server %s\n", 3203 storageNameOnServer); 3204 fprintf (stderr, "fileNameOnServer: %s\n", 3205 fileNameOnServer); 3206 #endif 3207 targetFile = 3208 open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, 3209 S_IRWXU | S_IRGRP | S_IROTH); 3210 if (targetFile < 0) 3211 { 3212 #ifdef DEBUG 3213 fprintf (stderr, "could not create the new file,%s\n", 3214 fileNameOnServer); 3215 #endif 3216 } 3217 else 3218 { 3219 while (cgiFormFileRead (file, buffer, BufferLen, &got) 3220 == cgiFormSuccess) 3221 { 3222 if (got > 0) 3223 write (targetFile, buffer, got); 3224 } 3225 } 3226 addToMap (tmpReqI->content, "lref", storageNameOnServer); 3227 cgiFormFileClose (file); 3228 close (targetFile); 3229 #ifdef DEBUG 3230 fprintf (stderr, "File \"%s\" has been uploaded", 3231 fileNameOnServer); 3232 #endif 3233 } 3234 } 3235 } 3236 tmpReqI = tmpReqI->next; 3237 } 3238 3239 ensureDecodedBase64 (&request_input_real_format); 3240 3241 #ifdef DEBUG 3242 fprintf (stderr, "REQUEST_INPUTS\n"); 3243 dumpMaps (request_input_real_format); 3244 fprintf (stderr, "REQUEST_OUTPUTS\n"); 3245 dumpMaps (request_output_real_format); 3246 #endif 1621 1622 1623 if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){ 1624 freeMaps (&m); 1625 free (m); 1626 free (REQUEST); 1627 free (SERVICE_URL); 1628 InternetCloseHandle (&hInternet); 1629 freeService (&s1); 1630 free (s1); 1631 return 0; 1632 } 3247 1633 3248 1634 maps *curs = getMaps (m, "env"); … … 3490 1876 if (status == NULLMAP) 3491 1877 { 1878 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 1879 freeService (&s1); 1880 free (s1); 1881 freeMaps (&m); 1882 free (m); 1883 free (REQUEST); 1884 free (SERVICE_URL); 1885 freeMaps (&request_input_real_format); 1886 free (request_input_real_format); 1887 freeMaps (&request_output_real_format); 1888 free (request_output_real_format); 1889 freeMaps (&tmpmaps); 1890 free (tmpmaps); 1891 return -1; 1892 } 1893 3492 1894 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 3493 1895 &request_output_real_format, &eres); … … 3530 1932 else if (pid == 0) 3531 1933 { 3532 3533 3534 3535 1934 /** 1935 * son : have to close the stdout, stdin and stderr to let the parent 1936 * process answer to http client. 1937 */ 3536 1938 #ifndef WIN32 3537 1939 zSleep (1); … … 3586 1988 #endif 3587 1989 free (flog); 1990 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 1991 freeService (&s1); 1992 free (s1); 1993 freeMaps (&m); 1994 free (m); 1995 free (REQUEST); 1996 free (SERVICE_URL); 1997 freeMaps (&request_input_real_format); 1998 free (request_input_real_format); 1999 freeMaps (&request_output_real_format); 2000 free (request_output_real_format); 2001 freeMaps (&tmpmaps); 2002 free (tmpmaps); 2003 fflush (stdout); 2004 unlockShm (lid); 2005 fflush (stderr); 2006 return -1; 2007 } 3588 2008 /** 3589 2009 * set status to SERVICE_STARTED and flush stdout to ensure full
Note: See TracChangeset
for help on using the changeset viewer.