Changeset 654 for trunk/zoo-project/zoo-kernel/request_parser.c
- Timestamp:
- Jun 15, 2015, 1:47:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/request_parser.c
r640 r654 496 496 int k = 0; 497 497 int l = 0; 498 map* version=getMapFromMaps(*main_conf,"main","rversion"); 499 int vid=getVersionId(version->value); 498 500 for (k=0; k < nodes->nodeNr; k++) 499 501 { … … 504 506 { 505 507 // A specific Input node. 508 if(vid==1){ 509 tmpmaps = (maps *) malloc (MAPS_SIZE); 510 xmlChar *val = xmlGetProp (cur, BAD_CAST "id"); 511 tmpmaps->name = zStrdup ((char *) val); 512 tmpmaps->content = NULL; 513 tmpmaps->next = NULL; 514 } 515 506 516 xmlNodePtr cur2 = cur->children; 507 517 while (cur2 != NULL) … … 805 815 { 806 816 xmlNodePtr cur4 = cur2->children; 817 if(vid==1){ 818 // Get every dataEncodingAttributes from a Data node: 819 // mimeType, encoding, schema 820 const char *coms[3] = 821 { "mimeType", "encoding", "schema" }; 822 for (l = 0; l < 3; l++){ 823 xmlChar *val = 824 xmlGetProp (cur4, BAD_CAST coms[l]); 825 if (val != NULL && strlen ((char *) val) > 0){ 826 if (tmpmaps->content != NULL) 827 addToMap (tmpmaps->content,coms[l],(char *) val); 828 else 829 tmpmaps->content = 830 createMap (coms[l],(char *) val); 831 } 832 xmlFree (val); 833 } 834 while (cur4 != NULL){ 835 while(cur4 != NULL && 836 cur4->type != XML_CDATA_SECTION_NODE && 837 cur4->type != XML_TEXT_NODE) 838 cur4=cur4->next; 839 if(cur4!=NULL){ 840 if(cur4->content!=NULL) 841 if (tmpmaps->content != NULL) 842 addToMap (tmpmaps->content, "value", 843 (char *) cur4->content); 844 else 845 tmpmaps->content = 846 createMap ("value", (char *) cur4->content); 847 cur4=cur4->next; 848 } 849 } 850 } 851 852 807 853 while (cur4 != NULL) 808 854 { … … 897 943 while (cur5 != NULL 898 944 && cur5->type != XML_ELEMENT_NODE 899 && cur5->type != 900 XML_CDATA_SECTION_NODE) 945 && cur5->type != XML_CDATA_SECTION_NODE) 901 946 cur5 = cur5->next; 902 947 if (cur5 != NULL … … 995 1040 996 1041 /** 1042 * Parse outputs from XML nodes and store them in a maps (WPS version 2.0.0). 1043 * 1044 * @param main_conf the conf maps containing the main.cfg settings 1045 * @param request_inputs the map storing KVP raw value 1046 * @param request_output the maps to store the KVP pairs 1047 * @param doc the xmlDocPtr containing the original request 1048 * @param cur the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node 1049 * @param raw true if the node is RawDataOutput, false in case of ResponseDocument 1050 * @return 0 on success, -1 on failure 1051 */ 1052 int xmlParseOutputs2(maps** main_conf,map** request_inputs,maps** request_output,xmlDocPtr doc,xmlNodeSet* nodes){ 1053 int k = 0; 1054 int l = 0; 1055 for (k=0; k < nodes->nodeNr; k++){ 1056 maps *tmpmaps = NULL; 1057 xmlNodePtr cur = nodes->nodeTab[k]; 1058 if (cur->type == XML_ELEMENT_NODE){ 1059 maps *tmpmaps = (maps *) malloc (MAPS_SIZE); 1060 xmlChar *val = xmlGetProp (cur, BAD_CAST "id"); 1061 if(val!=NULL) 1062 tmpmaps->name = zStrdup ((char*)val); 1063 else 1064 tmpmaps->name = zStrdup ("unknownIdentifier"); 1065 tmpmaps->content = NULL; 1066 tmpmaps->next = NULL; 1067 const char ress[4][13] = 1068 { "mimeType", "encoding", "schema", "transmission" }; 1069 for (l = 0; l < 4; l++){ 1070 val = xmlGetProp (cur, BAD_CAST ress[l]); 1071 if (val != NULL && strlen ((char *) val) > 0) 1072 { 1073 if (tmpmaps->content != NULL) 1074 addToMap (tmpmaps->content, ress[l], 1075 (char *) val); 1076 else 1077 tmpmaps->content = 1078 createMap (ress[l], (char *) val); 1079 if(l==3 && strncasecmp((char*)val,"reference",xmlStrlen(val))==0) 1080 addToMap (tmpmaps->content,"asReference","true"); 1081 } 1082 xmlFree (val); 1083 } 1084 if (*request_output == NULL) 1085 *request_output = dupMaps(&tmpmaps); 1086 else 1087 addMapsToMaps(request_output,tmpmaps); 1088 } 1089 } 1090 } 1091 1092 /** 997 1093 * Parse outputs from XML nodes and store them in a maps. 998 1094 * … … 1225 1321 */ 1226 1322 int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){ 1323 1324 map* version=getMapFromMaps(*main_conf,"main","rversion"); 1325 int vid=getVersionId(version->value); 1326 1227 1327 xmlInitParser (); 1228 1328 xmlDocPtr doc = xmlParseMemory (post, cgiContentLength); … … 1232 1332 */ 1233 1333 xmlXPathObjectPtr tmpsptr = 1234 extractFromDoc (doc, "/*/*/*[local-name()='Input']");1334 extractFromDoc (doc, (vid==0?"/*/*/*[local-name()='Input']":"/*/*[local-name()='Input']")); 1235 1335 xmlNodeSet *tmps = tmpsptr->nodesetval; 1236 if( xmlParseInputs(main_conf,s,inputs,doc,tmps,hInternet)<0){1336 if(tmps==NULL || xmlParseInputs(main_conf,s,inputs,doc,tmps,hInternet)<0){ 1237 1337 xmlXPathFreeObject (tmpsptr); 1238 1338 xmlFreeDoc (doc); … … 1242 1342 xmlXPathFreeObject (tmpsptr); 1243 1343 1244 // Extract ResponseDocument / RawDataOutput from the XML Request 1245 tmpsptr = 1246 extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); 1247 bool asRaw = false; 1248 tmps = tmpsptr->nodesetval; 1249 if (tmps->nodeNr == 0) 1250 { 1251 xmlXPathFreeObject (tmpsptr); 1252 tmpsptr = 1253 extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); 1254 tmps = tmpsptr->nodesetval; 1255 asRaw = true; 1256 } 1257 if(tmps->nodeNr != 0){ 1258 if(xmlParseOutputs(main_conf,request_inputs,outputs,doc,tmps->nodeTab[0],asRaw)<0){ 1259 xmlXPathFreeObject (tmpsptr); 1260 xmlFreeDoc (doc); 1261 xmlCleanupParser (); 1262 return -1; 1344 if(vid==1){ 1345 tmpsptr = 1346 extractFromDoc (doc, "/*[local-name()='Execute']"); 1347 bool asRaw = false; 1348 tmps = tmpsptr->nodesetval; 1349 if(tmps->nodeNr > 0){ 1350 int k = 0; 1351 for (k=0; k < tmps->nodeNr; k++){ 1352 maps *tmpmaps = NULL; 1353 xmlNodePtr cur = tmps->nodeTab[k]; 1354 if (cur->type == XML_ELEMENT_NODE){ 1355 xmlChar *val = xmlGetProp (cur, BAD_CAST "mode"); 1356 if(val!=NULL) 1357 addToMap(*request_inputs,"mode",(char*)val); 1358 else 1359 addToMap(*request_inputs,"mode","auto"); 1360 val = xmlGetProp (cur, BAD_CAST "response"); 1361 if(val!=NULL){ 1362 addToMap(*request_inputs,"response",(char*)val); 1363 if(strncasecmp((char*)val,"raw",xmlStrlen(val))==0) 1364 addToMap(*request_inputs,"RawDataOutput",""); 1365 else 1366 addToMap(*request_inputs,"ResponseDocument",""); 1367 } 1368 else{ 1369 addToMap(*request_inputs,"response","document"); 1370 addToMap(*request_inputs,"ResponseDocument",""); 1371 } 1372 } 1373 } 1374 } 1375 xmlXPathFreeObject (tmpsptr); 1376 tmpsptr = 1377 extractFromDoc (doc, "/*/*[local-name()='Output']"); 1378 tmps = tmpsptr->nodesetval; 1379 if(tmps->nodeNr > 0){ 1380 if(xmlParseOutputs2(main_conf,request_inputs,outputs,doc,tmps)<0){ 1381 xmlXPathFreeObject (tmpsptr); 1382 xmlFreeDoc (doc); 1383 xmlCleanupParser (); 1384 return -1; 1385 } 1386 } 1387 } 1388 else{ 1389 // Extract ResponseDocument / RawDataOutput from the XML Request 1390 tmpsptr = 1391 extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']"); 1392 bool asRaw = false; 1393 tmps = tmpsptr->nodesetval; 1394 if (tmps->nodeNr == 0) 1395 { 1396 xmlXPathFreeObject (tmpsptr); 1397 tmpsptr = 1398 extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']"); 1399 tmps = tmpsptr->nodesetval; 1400 asRaw = true; 1401 } 1402 if(tmps->nodeNr != 0){ 1403 if(xmlParseOutputs(main_conf,request_inputs,outputs,doc,tmps->nodeTab[0],asRaw)<0){ 1404 xmlXPathFreeObject (tmpsptr); 1405 xmlFreeDoc (doc); 1406 xmlCleanupParser (); 1407 return -1; 1408 } 1263 1409 } 1264 1410 }
Note: See TracChangeset
for help on using the changeset viewer.