Changeset 917 for trunk/zoo-project/zoo-kernel/response_print.c
- Timestamp:
- May 7, 2019, 2:17:08 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
trunk/zoo-project/zoo-kernel/response_print.c
r889 r917 23 23 */ 24 24 25 #include "service.h" 25 26 #include "response_print.h" 26 27 #include "request_parser.h" … … 31 32 #else 32 33 #include "cpl_vsi.h" 34 #endif 35 #ifdef USE_CALLBACK 36 #include "service_callback.h" 33 37 #endif 34 38 … … 75 79 } 76 80 if(prefix!=NULL){ 77 char* tmp0= strdup(serv->name);81 char* tmp0=zStrdup(serv->name); 78 82 free(serv->name); 79 83 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); … … 179 183 nbNs++; 180 184 currId=0; 181 nsName[currId]= strdup(name);185 nsName[currId]=zStrdup(name); 182 186 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 183 187 }else{ … … 186 190 nbNs++; 187 191 currId=nbNs-1; 188 nsName[currId]= strdup(name);192 nsName[currId]=zStrdup(name); 189 193 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 190 194 } … … 251 255 if(soap!=NULL && strcasecmp(soap->value,"true")==0){ 252 256 int lNbNs=nbNs; 253 nsName[lNbNs]= strdup("soap");257 nsName[lNbNs]=zStrdup("soap"); 254 258 usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 255 259 nbNs++; 256 260 xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); 257 nsName[nbNs]= strdup("soap");261 nsName[nbNs]=zStrdup("soap"); 258 262 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 259 263 nbNs++; 260 nsName[nbNs]= strdup("xsi");264 nsName[nbNs]=zStrdup("xsi"); 261 265 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 262 266 nbNs++; … … 338 342 } 339 343 else{ 340 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");341 xmlAddChild(nc4,xmlNewText(BAD_CAST buff));342 344 if(dcount==0){ 343 345 if(vid==0){ 346 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 347 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 344 348 xmlAddChild(nc2,nc4); 345 349 xmlAddChild(nc1,nc2); … … 361 365 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 362 366 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 363 364 365 366 367 if(vid==0) 368 xmlAddChild(nc3,nc4); 369 else 370 xmlAddChild(nc1,nc4); 367 371 } 368 372 } … … 590 594 map* tmp=getMap(toto1->content,"serverAddress"); 591 595 if(tmp!=NULL){ 592 SERVICE_URL = strdup(tmp->value);596 SERVICE_URL = zStrdup(tmp->value); 593 597 } 594 598 else 595 SERVICE_URL = strdup("not_defined");599 SERVICE_URL = zStrdup("not_defined"); 596 600 } 597 601 else 598 SERVICE_URL = strdup("not_defined");602 SERVICE_URL = zStrdup("not_defined"); 599 603 600 604 for(j=0;j<nbSupportedRequests;j++){ … … 644 648 * @return the generated wps:ProcessOfferings xmlNodePtr 645 649 */ 646 void printGetCapabilitiesForProcess(registry *reg, maps* m,xml NodePtr nc,service* serv){650 void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){ 647 651 xmlNsPtr ns,ns_ows,ns_xml,ns_xlink; 648 xmlNodePtr n=NULL,nc1,nc2 ;652 xmlNodePtr n=NULL,nc1,nc2,nc3; 649 653 map* version=getMapFromMaps(m,"main","rversion"); 650 654 int vid=getVersionId(version->value); … … 667 671 limit=7; 668 672 } 673 nc3=NULL; 674 map* sType=getMap(serv->content,"serviceType"); 669 675 for(;i<limit;i+=2){ 670 676 if(capabilities[vid][i]==NULL) … … 682 688 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST tmp1->value); 683 689 } 684 else 685 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 690 else{ 691 if(i==3 && vid==1 && sType!=NULL && strstr(sType->value,"HPC")!=NULL) 692 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss"); 693 else 694 xmlNewNsProp(nc1,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 695 } 686 696 } 687 697 } … … 690 700 printDescription(nc1,ns_ows,serv->name,serv->content,vid); 691 701 tmp1=serv->metadata; 692 while(tmp1!=NULL){ 693 nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 694 xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 695 xmlAddChild(nc1,nc2); 696 tmp1=tmp1->next; 697 } 698 702 703 addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink,vid); 704 tmp1=serv->additional_parameters; 705 int fromDb=-1; 706 map* test=getMap(serv->content,"fromDb"); 707 if(test!=NULL && strncasecmp(test->value,"true",4)==0) 708 fromDb=1; 709 addAdditionalParameters(tmp1,doc,nc1,ns_ows,ns_xlink,fromDb); 710 711 if(nc3!=NULL) 712 xmlAddChild(nc1,nc3); 699 713 xmlAddChild(nc,nc1); 700 714 } 715 701 716 } 702 717 … … 708 723 * @param content the servive main content created from the zcfg file 709 724 * @param vid the version identifier (0 for 1.0.0 and 1 for 2.0.0) 710 */ 711 void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid){ 725 * @param serviceType string containing the current service type 726 */ 727 void attachAttributes(xmlNodePtr n,xmlNsPtr ns,map* content,int vid,map* serviceType){ 712 728 int limit=7; 713 729 for(int i=1;i<limit;i+=2){ … … 728 744 } 729 745 else{ 730 if( vid==0 && i>=2)731 xmlNew Prop(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]);746 if(i==3 && vid==1 && serviceType!=NULL && strstr(serviceType->value,"HPC")!=NULL) 747 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST "async-execute dismiss"); 732 748 else 733 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 734 } 749 if(vid==0 && i>=2) 750 xmlNewProp(n,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 751 else 752 xmlNewNsProp(n,ns,BAD_CAST capabilities[vid][i],BAD_CAST capabilities[vid][i+1]); 753 } 754 } 755 } 756 757 /** 758 * Add a Metadata node to any existing node. 759 * @param meta the map defining the additional parameters 760 * @param doc the XML document used 761 * @param nb the node to add the additional parameters 762 * @param ns_ows the OWS namespace 763 * @param ns_xlink the xlink namespace 764 * @param vid the version of WPS to use (0 for 1.0.0 and 1 for 2.0) 765 */ 766 void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int vid){ 767 int hasTitle=-1; 768 int hasValue=-1; 769 xmlNodePtr nc1; 770 map* oMeta=meta; 771 int isAdditionalParameters=-1; 772 int level=0; 773 map* test=getMap(meta,"title"); 774 if(test!=NULL) 775 level+=1; 776 test=getMap(meta,"href"); 777 if(test!=NULL) 778 level+=1; 779 test=getMap(meta,"role"); 780 if(test!=NULL) 781 level+=1; 782 if(count(oMeta)>level+1) 783 isAdditionalParameters=1; 784 char *ctitle=NULL; 785 while(meta!=NULL){ 786 if(hasTitle<0) 787 if(isAdditionalParameters<0) 788 nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 789 else 790 if(hasValue<0) 791 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 792 if(strncasecmp(meta->name,"title",5)==0 || 793 strcasecmp(meta->name,"href")==0 || 794 strcasecmp(meta->name,"role")==0 ){ 795 int index=5; 796 if(strncasecmp(meta->name,"title",5)==0){ 797 index=6; 798 hasTitle=1; 799 if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){ 800 xmlAddChild(nc,nc1); 801 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 802 free(ctitle); 803 ctitle=NULL; 804 } 805 if(ctitle==NULL){ 806 char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char)); 807 snprintf(tmp,index,"%s",meta->name); 808 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value); 809 free(tmp); 810 } 811 if(ctitle!=NULL) 812 free(ctitle); 813 ctitle=zStrdup(meta->value); 814 } 815 }else{ 816 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter"); 817 xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name"); 818 xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name)); 819 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 820 xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value)); 821 xmlAddChild(nc2,nc3); 822 xmlAddChild(nc2,nc4); 823 xmlAddChild(nc1,nc2); 824 hasTitle=-1; 825 } 826 meta=meta->next; 827 if(hasTitle<0){ 828 hasValue=1; 829 if(isAdditionalParameters){ 830 if(vid==0){ 831 meta=NULL; 832 break; 833 }else 834 xmlAddChild(nc,nc1); 835 } 836 } 837 } 838 if(oMeta!=NULL && hasValue<0 && nc1!=NULL){ 839 xmlAddChild(nc,nc1); 840 } 841 } 842 843 /** 844 * Add AdditionalParameters nodes to any existing node. 845 * @param meta the map defining the additional parameters 846 * @param doc the XML document used 847 * @param nb the node to add the additional parameters 848 * @param ns_ows the OWS namespace 849 * @param ns_xlink the xlink namespace 850 * @param fromDb 1 if the metadata has been extracted from the metadb, 851 * 0 otherwise 852 */ 853 void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){ 854 int hasTitle=-1; 855 int hasValue=-1; 856 int toAddAtEnd=-1; 857 int cnt=0; 858 xmlNodePtr* ncr=NULL; 859 xmlNodePtr nc1; 860 map* oMeta=meta; 861 int isAdditionalParameters=-1; 862 int level=0; 863 map* test=getMap(meta,"title"); 864 map* otitle=getMap(meta,"title"); 865 map* length=getMap(meta,"length"); 866 int len=0; 867 char *ctitle=NULL; 868 869 if(test!=NULL) 870 level+=1; 871 test=getMap(meta,"href"); 872 if(test!=NULL) 873 level+=1; 874 test=getMap(meta,"role"); 875 if(test!=NULL) 876 level+=1; 877 if(count(oMeta)>level+1) 878 isAdditionalParameters=1; 879 880 while(meta!=NULL){ 881 if(hasTitle<0 && hasValue<0){ 882 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 883 } 884 if(strncasecmp(meta->name,"title",5)==0 || 885 strcasecmp(meta->name,"href")==0 || 886 strcasecmp(meta->name,"role")==0 ){ 887 int index=5; 888 if(strncasecmp(meta->name,"title",5)==0){ 889 index=6; 890 hasTitle=1; 891 if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){ 892 xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1); 893 xmlAddChild(nc,ncTmp); 894 xmlFreeNode(nc1); 895 toAddAtEnd=1; 896 cnt++; 897 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 898 free(ctitle); 899 ctitle=NULL; 900 } 901 if(ctitle==NULL){ 902 char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char)); 903 snprintf(tmp,index,"%s",meta->name); 904 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value); 905 free(tmp); 906 } 907 if(ctitle!=NULL) 908 free(ctitle); 909 ctitle=zStrdup(meta->value); 910 }else{ 911 xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value); 912 } 913 }else{ 914 if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){ 915 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter"); 916 xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name"); 917 xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name)); 918 xmlAddChild(nc2,nc3); 919 if(fromDb<0){ 920 char *mptr; 921 char* meta_values=strtok_r(meta->value,",",&mptr); 922 while(meta_values!=NULL){ 923 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 924 xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values)); 925 xmlAddChild(nc2,nc4); 926 meta_values=strtok_r(NULL,",",&mptr); 927 } 928 }else{ 929 xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value"); 930 xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value))); 931 xmlAddChild(nc2,nc4); 932 } 933 xmlAddChild(nc1,nc2); 934 } 935 hasTitle=-1; 936 } 937 meta=meta->next; 938 if(hasTitle<0){ 939 //xmlAddChild(nc,nc1); 940 hasValue=1; 941 }/*else 942 if(ctitle!=NULL) 943 free(ctitle);*/ 944 } 945 if(length!=NULL) 946 len=atoi(length->value); 947 if(otitle!=NULL) 948 len=1; 949 if(cnt<len){ 950 xmlAddChild(nc,nc1); 951 free(ctitle); 735 952 } 736 953 } … … 792 1009 * @return the generated wps:ProcessOfferings xmlNodePtr 793 1010 */ 794 void printDescribeProcessForProcess(registry *reg, maps* m,xml NodePtr nc,service* serv){1011 void printDescribeProcessForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){ 795 1012 xmlNsPtr ns,ns_ows,ns_xlink; 796 1013 xmlNodePtr n,nc1; … … 798 1015 map* version=getMapFromMaps(m,"main","rversion"); 799 1016 int vid=getVersionId(version->value); 1017 int fromDb=-1; 1018 map* serviceType=getMap(serv->content,"serviceType"); 1019 map* test=getMap(serv->content,"fromDb"); 1020 if(test!=NULL && strncasecmp(test->value,"true",4)==0) 1021 fromDb=1; 800 1022 801 1023 n=nc; … … 811 1033 if(vid==0){ 812 1034 nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); 813 attachAttributes(nc,ns,serv->content,vid );1035 attachAttributes(nc,ns,serv->content,vid,NULL); 814 1036 } 815 1037 else{ … … 828 1050 } 829 1051 } 830 attachAttributes(nc2,NULL,serv->content,vid );1052 attachAttributes(nc2,NULL,serv->content,vid,serviceType); 831 1053 map* level=getMap(serv->content,"level"); 832 1054 if(level!=NULL && strcasecmp(level->value,"generic")==0) … … 843 1065 tmp1=serv->metadata; 844 1066 while(tmp1!=NULL){ 845 nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 846 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 847 xmlAddChild(nc,nc1); 1067 addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid); 848 1068 tmp1=tmp1->next; 849 1069 } … … 855 1075 } 856 1076 }else{ 1077 tmp1=serv->metadata; 1078 addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid); 857 1079 addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv); 1080 tmp1=serv->additional_parameters; 1081 if(vid!=0) 1082 addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb); 858 1083 } 859 1084 … … 862 1087 if(vid==0){ 863 1088 nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); 864 printFullDescription( 1,e,"Input",ns,ns_ows,nc1,vid);1089 printFullDescription(doc,1,e,"Input",ns,ns_ows,nc1,vid,fromDb,NULL); 865 1090 xmlAddChild(nc,nc1); 866 1091 } 867 1092 else{ 868 printFullDescription( 1,e,"wps:Input",ns,ns_ows,nc,vid);1093 printFullDescription(doc,1,e,"wps:Input",ns,ns_ows,nc,vid,fromDb,NULL); 869 1094 } 870 1095 } … … 873 1098 if(vid==0){ 874 1099 nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); 875 printFullDescription( 0,e,"Output",ns,ns_ows,nc1,vid);1100 printFullDescription(doc,0,e,"Output",ns,ns_ows,nc1,vid,fromDb,NULL); 876 1101 xmlAddChild(nc,nc1); 877 1102 } 878 1103 else{ 879 printFullDescription( 0,e,"wps:Output",ns,ns_ows,nc,vid);1104 printFullDescription(doc,0,e,"wps:Output",ns,ns_ows,nc,vid,fromDb,serviceType); 880 1105 } 881 1106 if(vid==0) … … 899 1124 * @param nc1 the XML node to use to add the created tree 900 1125 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0) 901 */ 902 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){ 1126 * @param fromDb 1 in case the metadata comes from the DB, -1 in other cases 1127 * @param serviceType the serviceType found in the ZCFG file or the DB 1128 */ 1129 void printFullDescription(xmlDocPtr doc,int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid,int fromDb,const map* serviceType){ 903 1130 xmlNsPtr ns1=NULL; 904 1131 if(vid==1) … … 913 1140 int isAnyValue=1; 914 1141 nc2 = xmlNewNode(NULL, BAD_CAST type); 1142 // Extract min/max Occurence information 915 1143 if(strstr(type,"Input")!=NULL){ 916 1144 tmp1=getMap(e->content,"minOccurs"); … … 935 1163 936 1164 if(e->format!=NULL){ 1165 #ifdef USE_HPC 1166 DEFAULT_OUT: 1167 #endif 937 1168 const char orderedFields[13][14]={ 938 1169 "mimeType", … … 952 1183 //Build the (Literal/Complex/BoundingBox)Data node 953 1184 if(strncmp(type,"Output",6)==0){ 954 if(strncasecmp(e->format,"LITERAL DATA",strlen(e->format))==0)1185 if(strncasecmp(e->format,"LITERAL",7)==0) 955 1186 nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput"); 956 1187 else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) … … 998 1229 strcmp(e->format,"BoundingBoxData")==0){ 999 1230 datatype=2; 1000 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1231 if(vid==0) 1232 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1233 else{ 1234 xmlNodePtr nc6 = xmlNewNode(ns1, BAD_CAST "Format"); 1235 xmlNewProp(nc6,BAD_CAST "mimeType",BAD_CAST "text/xml"); 1236 xmlNewProp(nc6,BAD_CAST "default",BAD_CAST "true"); 1237 xmlAddChild(nc3,nc6); 1238 nc5 = xmlNewNode(NULL, BAD_CAST "SupportedCRS"); 1239 } 1001 1240 } 1002 1241 else{ … … 1039 1278 while(token!=NULL){ 1040 1279 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1041 char *tmps= strdup(token);1280 char *tmps=zStrdup(token); 1042 1281 tmps[strlen(tmps)]=0; 1043 xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); 1282 nc8 = xmlNewText(BAD_CAST tmps); 1283 xmlAddChild(nc7,nc8); 1044 1284 free(tmps); 1045 1285 xmlAddChild(nc6,nc7); … … 1207 1447 strncasecmp(tmp1->name,"range",5)!=0){ 1208 1448 if(datatype!=1){ 1209 char *tmp2=zCapitalize1(tmp1->name); 1210 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1211 free(tmp2); 1449 if(datatype==2 && vid==1){ 1450 nc9 = xmlNewNode(ns, BAD_CAST "SupportedCRS"); 1451 xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true"); 1452 } 1453 else{ 1454 char *tmp2=zCapitalize1(tmp1->name); 1455 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1456 free(tmp2); 1457 } 1212 1458 } 1213 1459 else{ … … 1218 1464 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1219 1465 if(vid==0 || oI>=3){ 1220 if(vid==0 || oI!=4) 1221 xmlAddChild(nc5,nc9); 1466 if(vid==0 || oI!=4){ 1467 if(datatype==2 && vid==1) 1468 xmlAddChild(nc3,nc9); 1469 else 1470 xmlAddChild(nc5,nc9); 1471 } 1222 1472 if(oI==4 && vid==1){ 1223 1473 xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true"); 1224 1474 } 1225 1475 } 1226 else 1227 xmlFree(nc9); 1476 else{ 1477 xmlFreeNode(nc9); 1478 } 1228 1479 if(strcasecmp(tmp1->name,"uom")==0) 1229 1480 hasUOM1=true; 1230 1481 hasUOM=true; 1231 }else 1232 tmp1=tmp1->next; 1482 } 1233 1483 } 1234 1484 } … … 1245 1495 }else{ 1246 1496 if(hasUOM1==false && vid==0){ 1247 xmlFreeNode(nc5); 1248 if(datatype==1) 1497 if(nc5!=NULL) 1498 xmlFreeNode(nc5); 1499 if(datatype==1){ 1249 1500 xmlFreeNode(nc4); 1501 } 1250 1502 } 1251 else 1503 else{ 1252 1504 xmlAddChild(nc3,nc5); 1505 } 1253 1506 } 1254 1507 }else{ 1255 xmlAddChild(nc3,nc5); 1508 if(vid==0) 1509 xmlAddChild(nc3,nc5); 1510 else 1511 xmlFreeNode(nc5); 1256 1512 } 1257 1513 1258 if(datatype !=1&& default1<0){1514 if(datatype==0 && default1<0){ 1259 1515 xmlFreeNode(nc5); 1260 if(datatype!=2) 1516 if(datatype!=2){ 1261 1517 xmlFreeNode(nc4); 1518 } 1262 1519 } 1263 1520 … … 1310 1567 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); 1311 1568 free(tmp2); 1312 //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");1313 1569 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1314 1570 xmlAddChild(nc5,nc9); 1315 /*struct iotype * _ltmp=e->supported;1316 while(_ltmp!=NULL){1317 tmp1=getMap(_ltmp->content,"uom");1318 if(tmp1!=NULL){1319 char *tmp2=zCapitalize(tmp1->name);1320 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);1321 free(tmp2);1322 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));1323 xmlAddChild(nc5,nc9);1324 }1325 _ltmp=_ltmp->next;1326 }*/1327 1328 1571 } 1329 1572 } … … 1340 1583 xmlNsPtr ns_xlink=usedNs[xlinkId]; 1341 1584 1342 while(metadata!=NULL){ 1343 nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata"); 1344 xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value); 1345 xmlAddChild(nc2,nc6); 1346 metadata=metadata->next; 1347 } 1585 addMetadata(metadata,doc,nc2,ns_ows,ns_xlink,vid); 1586 if(vid!=0) 1587 addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb); 1348 1588 1349 1589 } 1350 1590 1351 1591 _tmp=e->supported; 1352 if(_tmp==NULL && datatype !=1)1592 if(_tmp==NULL && datatype==0) 1353 1593 _tmp=e->defaults; 1354 1594 … … 1396 1636 strcasecmp(tmp1->name,"extension")!=0){ 1397 1637 if(datatype!=1){ 1398 char *tmp2=zCapitalize1(tmp1->name); 1399 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1400 free(tmp2); 1638 if(datatype==2 && vid==1){ 1639 nc6 = xmlNewNode(ns, BAD_CAST "SupportedCRS"); 1640 } 1641 else{ 1642 char *tmp2=zCapitalize1(tmp1->name); 1643 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1644 free(tmp2); 1645 } 1401 1646 } 1402 1647 else{ … … 1422 1667 } 1423 1668 if(vid==0 || oI>=3){ 1424 if(vid==0 || oI!=4) 1425 xmlAddChild(nc5,nc6); 1426 else 1427 xmlFree(nc6); 1669 if(vid==0 || oI!=4){ 1670 if(datatype==2 && vid==1) 1671 xmlAddChild(nc3,nc6); 1672 else 1673 xmlAddChild(nc5,nc6); 1674 } 1675 else{ 1676 xmlFreeNode(nc6); 1677 } 1428 1678 } 1429 else 1430 xmlFree(nc6); 1679 else{ 1680 xmlFreeNode(nc6); 1681 } 1431 1682 } 1432 1683 tmp1=tmp1->next; … … 1439 1690 } 1440 1691 else{ 1441 xmlAddChild(nc3,nc5); 1692 if(datatype!=2) 1693 xmlAddChild(nc3,nc5); 1442 1694 } 1443 1695 1444 1696 }else{ 1445 if(datatype !=1)1697 if(datatype==2 && vid==0) 1446 1698 xmlAddChild(nc3,nc5); 1447 1699 } … … 1459 1711 } 1460 1712 else 1461 if(datatype!=1) 1713 if(datatype==0){ 1714 xmlFreeNode(nc4); 1462 1715 xmlAddChild(nc3,nc5); 1716 } 1463 1717 1464 1718 _tmp=_tmp->next; … … 1466 1720 1467 1721 if(hasSupported==0){ 1468 if(datatype==0 && vid!=0) 1722 if(datatype==0 && vid!=0){ 1469 1723 xmlFreeNode(nc4); 1724 } 1470 1725 xmlFreeNode(nc5); 1471 1726 } … … 1478 1733 } 1479 1734 else{ 1735 xmlFreeNode(nc4); 1480 1736 xmlAddChild(nc3,nc5); 1481 1737 } … … 1491 1747 }else{ 1492 1748 if(e->child!=NULL && vid!=0){ 1493 printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid); 1494 } 1495 } 1496 1749 printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL); 1750 } 1751 } 1497 1752 if(e->child!=NULL && vid==0){ 1498 1753 elements* children=dupElements(e->child); 1499 1754 elements* cursor=children; 1500 1755 while(cursor!=NULL){ 1501 char* tmp=strdup(cursor->name); 1502 free(cursor->name); 1503 cursor->name=(char*)malloc((strlen(cursor->name)+strlen(e->name)+2)*sizeof(char)); 1504 sprintf(cursor->name,"%s.%s",e->name,tmp); 1756 elements* ccursor=cursor; 1757 char* tmp=zStrdup(ccursor->name); 1758 free(ccursor->name); 1759 ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char)); 1760 sprintf(ccursor->name,"%s.%s",e->name,tmp); 1505 1761 cursor=cursor->next; 1506 1762 } 1507 printFullDescription(in,children,type,ns,ns_ows,nc2,vid); 1508 xmlAddChild(nc1,nc2); 1763 printFullDescription(doc,in,children,type,ns,ns_ows,nc1,vid,fromDb,serviceType); 1509 1764 freeElements(&children); 1510 1765 free(children); 1511 }else 1512 xmlAddChild(nc1,nc2); 1513 1766 }else{ 1767 if(nc2!=NULL){ 1768 xmlAddChild(nc1,nc2); 1769 } 1770 } 1514 1771 e=e->next; 1515 1772 } … … 1528 1785 * @param outputs the outputs generated by the service 1529 1786 */ 1530 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1787 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1531 1788 xmlNsPtr ns,ns_ows,ns_xlink; 1532 1789 xmlNodePtr nr,n,nc,nc1=NULL,nc3; … … 1549 1806 char stored_path[1024]; 1550 1807 memset(stored_path,0,1024); 1551 1808 1552 1809 if(vid==0){ 1553 1810 char tmp[256]; … … 1734 1991 } 1735 1992 } 1736 1993 1737 1994 /** 1738 1995 * Display the process output only when requested ! … … 1744 2001 maps* mcursor=outputs; 1745 2002 elements* scursor=serv->outputs; 1746 map* testResponse=getMap(request,"RawDataOutput"); 2003 map* testResponse=getMap(request,"RawDataOutput"); 1747 2004 if(testResponse==NULL) 1748 2005 testResponse=getMap(request,"ResponseDocument"); 1749 while(mcursor!=NULL){ 2006 while(mcursor!=NULL){ 1750 2007 map* tmp0=getMap(mcursor->content,"inRequest"); 1751 scursor=getElements(serv->outputs,mcursor->name); 1752 if(scursor!=NULL){ 1753 if(testResponse==NULL || tmp0==NULL){ 2008 scursor=getElements(serv->outputs,mcursor->name); 2009 if(scursor!=NULL){ 2010 if(testResponse==NULL || tmp0==NULL){ 1754 2011 if(vid==0) 1755 2012 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); … … 1758 2015 } 1759 2016 else 1760 1761 if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){ 2017 if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){ 1762 2018 if(vid==0) 1763 2019 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1764 2020 else 1765 2021 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1766 } 2022 } 1767 2023 }else 1768 2024 /** … … 1775 2031 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 1776 2032 mcursor=mcursor->next; 1777 } 2033 } 1778 2034 if(vid==0) 1779 2035 xmlAddChild(n,nc); 1780 } 1781 2036 } 1782 2037 if(vid==0 && 1783 2038 hasStoredExecuteResponse==true … … 1834 2089 #endif 1835 2090 } 2091 1836 2092 printDocument(m,doc,pid); 1837 2093 … … 1891 2147 else{ 1892 2148 /* 1893 dumpElements(e);2149 dumpElements(e); 1894 2150 */ 1895 2151 return; … … 1900 2156 || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 1901 2157 || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) 1902 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);2158 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); 1903 2159 tmp=tmp->next; 1904 2160 } … … 1927 2183 * @param type the type 1928 2184 */ 1929 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){ 1930 2185 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){ 1931 2186 xmlNodePtr nc1,nc2,nc3; 1932 2187 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1935 2190 tmp=e->content; 1936 2191 else 1937 tmp=m->content; 1938 2192 tmp=m->content; 1939 2193 if(vid==0){ 1940 2194 nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); … … 1976 2230 xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name)); 1977 2231 } 1978 2232 1979 2233 // IO type nested outputs 1980 if(m->child!=NULL){ 2234 if(m->child!=NULL){ 1981 2235 maps* curs=m->child; 1982 2236 elements* ecurs=getElements(e,(e!=NULL?e->name:m->name)); 1983 2237 ecurs=ecurs->child; 1984 while(curs!=NULL ){2238 while(curs!=NULL/* && ecurs!=NULL*/){ 1985 2239 ecurs=getElements(ecurs,(curs->name)); 1986 2240 map* inRequest=getMap(curs->content,"inRequest"); … … 1992 2246 } 1993 2247 } 1994 else{ 2248 else{ 1995 2249 map *tmpMap=getMap(m->content,"Reference"); 1996 if(tmpMap==NULL){ 2250 if(tmpMap==NULL){ 1997 2251 nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); 1998 if(e!=NULL && e->format!=NULL){ 1999 if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)2000 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");2252 if(e!=NULL && e->format!=NULL){ 2253 if (strncasecmp(e->format, "LiteralOutput", strlen(e->format)) == 0) 2254 nc3 = xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2001 2255 else 2002 2256 if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) … … 2005 2259 nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); 2006 2260 else 2007 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 2008 } 2009 else { 2010 map* tmpV=getMapFromMaps(m,"format","value"); 2261 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 2262 } 2263 else { 2264 map* tmpV=getMapFromMaps(m,"format","value"); 2011 2265 if(tmpV!=NULL) 2012 2266 nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); … … 2014 2268 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2015 2269 } 2016 tmp=m->content; 2017 2270 tmp=m->content; 2271 2018 2272 while(tmp!=NULL){ 2019 2273 if(strcasecmp(tmp->name,"mimeType")==0 || … … 2021 2275 strcasecmp(tmp->name,"schema")==0 || 2022 2276 strcasecmp(tmp->name,"datatype")==0 || 2023 strcasecmp(tmp->name,"uom")==0) { 2024 2277 strcasecmp(tmp->name,"uom")==0) { 2025 2278 if(vid==0) 2026 2279 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); … … 2033 2286 } 2034 2287 } 2288 2035 2289 if(vid==0) 2036 2290 xmlAddChild(nc2,nc3); 2037 tmp=tmp->next; 2291 tmp=tmp->next; 2038 2292 } 2039 2293 if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) { … … 2046 2300 } 2047 2301 } 2048 else { 2049 if(e!=NULL) 2050 tmp=getMap(e->defaults->content,"mimeType"); 2302 else { 2303 //if (e != NULL) { 2304 if (e != NULL && e->defaults != NULL) { // knut: add extra NULL pointer check in case user omits <Default> block in config file 2305 tmp = getMap(e->defaults->content, "mimeType"); 2306 } 2051 2307 else 2052 tmp=NULL; 2053 2308 tmp=NULL; 2054 2309 map* tmp1=getMap(m->content,"encoding"); 2055 2310 map* tmp2=getMap(m->content,"mimeType"); … … 2106 2361 strstr(tmp2->value, "json") != NULL || // (will not be parsed by XML reader) 2107 2362 strstr(tmp2->value, "ecmascript") != NULL 2108 ) {2363 ) { 2109 2364 xmlAddChild((vid==0?nc3:nc2),xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); 2110 2365 } … … 2112 2367 if (strstr(tmp2->value, "xml") != NULL || // if XML-based format 2113 2368 // include for backwards compatibility, 2114 2369 // although correct mime type is ...kml+xml: 2115 2370 strstr(tmp2->value, "google-earth.kml") != NULL 2116 2371 ) { … … 2241 2496 else 2242 2497 exceptionCode="501 Internal Server Error"; 2243 2498 tmp=getMapFromMaps(m,"lenv","status_code"); 2499 if(tmp!=NULL) 2500 exceptionCode=tmp->value; 2244 2501 if(m!=NULL){ 2245 2502 map *tmpSid=getMapFromMaps(m,"lenv","sid"); … … 2332 2589 2333 2590 tmp=getMapArray(s,"text",cnt); 2591 if(tmp==NULL) 2592 tmp=getMapArray(s,"message",cnt); 2334 2593 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2335 2594 if(tmp!=NULL){ 2336 2595 xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); 2337 2596 xmlAddChild(nc1,txt); 2597 if(cnt==0) 2598 setMapInMaps(m,"lenv","message",tmp->value); 2338 2599 } 2339 2600 else{ … … 2381 2642 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, 2382 2643 map* request_inputs1,int cpid,maps* m,int res){ 2383 2384 2644 #ifdef DEBUG 2385 2645 dumpMaps(request_inputs); 2386 2646 dumpMaps(request_outputs); 2387 2647 fprintf(stderr,"printProcessResponse\n"); 2388 #endif 2648 #endif 2389 2649 map* toto=getMap(request_inputs1,"RawDataOutput"); 2390 2650 int asRaw=0; … … 2396 2656 if(tmpSess!=NULL){ 2397 2657 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 2658 maps *tmps=getMaps(m,"senv"); 2398 2659 char* sessId=NULL; 2399 2660 if(_tmp!=NULL){ 2400 2661 printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value); 2662 map *_tmp1=getMapFromMaps(m,"senv","ecookie_length"); 2663 if(_tmp1!=NULL){ 2664 int len=atoi(_tmp1->value); 2665 int cnt=0; 2666 for(cnt=0;cnt<len;cnt++){ 2667 map* _tmp2=getMapArray(tmps->content,"ecookie",cnt); 2668 if(_tmp2!=NULL) 2669 printf("Set-Cookie: %s; HttpOnly\r\n",_tmp2->value); 2670 } 2671 } 2401 2672 printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 2402 2673 char session_file_path[100]; … … 2406 2677 else 2407 2678 sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1); 2408 sessId= strdup(session_file_path);2679 sessId=zStrdup(session_file_path); 2409 2680 }else{ 2410 2681 maps* t=getMaps(m,"senv"); … … 2412 2683 while(p!=NULL){ 2413 2684 if(strstr(p->name,"ID")!=NULL){ 2414 sessId= strdup(p->value);2685 sessId=zStrdup(p->value); 2415 2686 break; 2416 2687 } … … 2435 2706 } 2436 2707 } 2437 2438 2708 if(res==SERVICE_FAILED){ 2439 2709 map *lenv; … … 2462 2732 return; 2463 2733 } 2464 2734 2735 if(res!=SERVICE_SUCCEEDED){ 2736 printProcessResponse(m,request_inputs1,cpid, 2737 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2738 request_inputs, 2739 request_outputs); 2740 return; 2741 } 2742 2465 2743 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2466 2744 if(asRaw==0){ … … 2473 2751 map* usid=getMapFromMaps(m,"lenv","usid"); 2474 2752 int itn=0; 2753 int error=-1; 2475 2754 NESTED0: 2476 2755 while(tmpI!=NULL){ … … 2483 2762 #endif 2484 2763 map *gfile=getMap(tmpI->content,"generated_file"); 2485 char *file_name ;2764 char *file_name=NULL; 2486 2765 if(gfile!=NULL){ 2487 2766 gfile=getMap(tmpI->content,"expected_generated_file"); … … 2491 2770 readGeneratedFile(m,tmpI->content,gfile->value); 2492 2771 file_name=zStrdup((gfile->value)+strlen(tmp1->value)); 2493 } 2494 2772 } 2495 2773 toto=getMap(tmpI->content,"asReference"); 2496 2774 #ifdef USE_MS 2497 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL) 2775 map* geodatatype=getMap(tmpI->content,"geodatatype"); 2776 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && 2777 (testMap==NULL || 2778 strncasecmp(testMap->value,"true",4)!=0 || 2779 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 2498 2780 #else 2499 2781 if(toto!=NULL && strcasecmp(toto->value,"true")==0) 2500 2782 #endif 2501 { 2502 elements* in=getElements(s->outputs,tmpI->name); 2503 if(in==NULL && s->outputs->child!=NULL){ 2504 in=getElements(s->outputs->child,tmpI->name); 2783 { 2784 elements* in=getElements(s->outputs,tmpI->name); 2785 if(in==NULL && s->outputs->child!=NULL){ 2786 in=getElements(s->outputs->child,tmpI->name); 2787 } 2788 char *format=NULL; 2789 if(in!=NULL && in->format!=NULL){ 2790 format=in->format; 2791 }else 2792 format=(char*)"LiteralData"; 2793 if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){ 2794 addToMap(tmpI->content,"extension","xml"); 2795 addToMap(tmpI->content,"mimeType","text/xml"); 2796 addToMap(tmpI->content,"encoding","UTF-8"); 2797 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2798 } 2799 char *file_path=NULL; 2800 if(gfile==NULL) { 2801 map *ext=getMap(tmpI->content,"extension"); 2802 char file_ext[32]; 2803 2804 if( ext != NULL && ext->value != NULL) { 2805 strncpy(file_ext, ext->value, 32); 2806 } 2807 else { 2808 // Obtain default file extension (see mimetypes.h). 2809 // If the MIME type is not recognized, txt is used as the default extension 2810 map* mtype=getMap(tmpI->content,"mimeType"); 2811 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2812 } 2813 if(file_name!=NULL) 2814 free(file_name); 2815 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2816 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2817 itn++; 2818 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2819 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2820 2821 FILE *ofile=fopen(file_path,"wb"); 2822 if(ofile==NULL){ 2823 char tmpMsg[1024]; 2824 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name); 2825 errorException(m,tmpMsg,"InternalError",NULL); 2826 free(file_name); 2827 free(file_path); 2828 return; 2829 } 2830 2831 toto=getMap(tmpI->content,"value"); 2832 if(toto==NULL){ 2833 char tmpMsg[1024]; 2834 sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name); 2835 errorException(m,tmpMsg,"InternalError",NULL); 2836 fclose(ofile); 2837 free(file_name); 2838 free(file_path); 2839 return; 2840 } 2841 if(strcasecmp(format,"BoundingBoxData")!=0){ 2842 map* size=getMap(tmpI->content,"size"); 2843 if(size!=NULL && toto!=NULL) 2844 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); 2845 else 2846 if(toto!=NULL && toto->value!=NULL) 2847 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2848 }else{ 2849 printBoundingBoxDocument(m,tmpI,ofile); 2850 } 2851 fclose(ofile); 2852 } 2853 2854 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2855 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2856 char *file_url=NULL; 2857 if(strncasecmp(tmp2->value,"http://",7)==0 || 2858 strncasecmp(tmp2->value,"https://",8)==0){ 2859 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2860 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2861 }else{ 2862 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2863 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2864 } 2865 addToMap(tmpI->content,"Reference",file_url); 2866 if(file_name!=NULL) 2867 free(file_name); 2868 if(file_url!=NULL) 2869 free(file_url); 2870 file_name=NULL; 2505 2871 } 2506 char *format=NULL; 2507 if(in!=NULL && in->format!=NULL){ 2508 format=in->format; 2509 }else 2510 format=(char*)"LiteralData"; 2511 if(format!=NULL && strcasecmp(format,"BoundingBoxData")==0){ 2512 addToMap(tmpI->content,"extension","xml"); 2513 addToMap(tmpI->content,"mimeType","text/xml"); 2514 addToMap(tmpI->content,"encoding","UTF-8"); 2515 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2872 #ifdef USE_MS 2873 else{ 2874 if(testMap!=NULL){ 2875 map* nbFeatures; 2876 setMapInMaps(m,"lenv","state","out"); 2877 setReferenceUrl(m,tmpI); 2878 nbFeatures=getMap(tmpI->content,"nb_features"); 2879 geodatatype=getMap(tmpI->content,"geodatatype"); 2880 if((nbFeatures!=NULL && atoi(nbFeatures->value)==0) || 2881 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)){ 2882 error=1; 2883 res=SERVICE_FAILED; 2884 } 2516 2885 } 2517 2518 if(gfile==NULL) { 2519 map *ext=getMap(tmpI->content,"extension"); 2520 char *file_path; 2521 char file_ext[32]; 2522 2523 if( ext != NULL && ext->value != NULL) { 2524 strncpy(file_ext, ext->value, 32); 2525 } 2526 else { 2527 // Obtain default file extension (see mimetypes.h). 2528 // If the MIME type is not recognized, txt is used as the default extension 2529 map* mtype=getMap(tmpI->content,"mimeType"); 2530 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2531 } 2532 2533 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2534 sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2535 itn++; 2536 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2537 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2538 2539 FILE *ofile=fopen(file_path,"wb"); 2540 if(ofile==NULL){ 2541 char tmpMsg[1024]; 2542 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name); 2543 errorException(m,tmpMsg,"InternalError",NULL); 2544 free(file_name); 2545 free(file_path); 2546 return; 2547 } 2548 free(file_path); 2549 2550 toto=getMap(tmpI->content,"value"); 2551 if(strcasecmp(format,"BoundingBoxData")!=0){ 2552 map* size=getMap(tmpI->content,"size"); 2553 if(size!=NULL && toto!=NULL) 2554 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile); 2555 else 2556 if(toto!=NULL && toto->value!=NULL) 2557 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2558 }else{ 2559 printBoundingBoxDocument(m,tmpI,ofile); 2560 } 2561 fclose(ofile); 2562 2563 } 2564 2565 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2566 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2567 char *file_url; 2568 if(strncasecmp(tmp2->value,"http://",7)==0 || 2569 strncasecmp(tmp2->value,"https://",8)==0){ 2570 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2571 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2572 }else{ 2573 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2574 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2575 } 2576 addToMap(tmpI->content,"Reference",file_url); 2577 free(file_name); 2578 free(file_url); 2579 2580 } 2581 #ifdef USE_MS 2582 else{ 2583 if(testMap!=NULL){ 2584 setReferenceUrl(m,tmpI); 2585 } 2586 } 2587 #endif 2886 } 2887 #endif 2888 if(file_name!=NULL){ 2889 free(file_name); 2890 file_name=NULL; 2891 } 2588 2892 tmpI=tmpI->next; 2589 2893 } … … 2593 2897 if(tmpI!=NULL) 2594 2898 goto NESTED0; 2595 } 2899 } 2596 2900 #ifdef DEBUG 2597 2901 fprintf(stderr,"SERVICE : %s\n",s->name); 2598 2902 dumpMaps(m); 2903 #endif 2904 if(error<0) 2905 printProcessResponse(m,request_inputs1,cpid, 2906 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2907 request_inputs, 2908 request_outputs); 2909 else{ 2910 maps* tmpMaps=getMaps(m,"lenv"); 2911 #ifdef USE_CALLBACK 2912 invokeCallback(m,NULL,NULL,7,0); 2599 2913 #endif 2600 printProcessResponse(m,request_inputs1,cpid, 2601 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2602 request_inputs, 2603 request_outputs); 2914 printExceptionReportResponse(m,tmpMaps->content); 2915 } 2604 2916 } 2605 2917 else{
Note: See TracChangeset
for help on using the changeset viewer.