Changeset 576 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Feb 11, 2015, 11:29:35 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r565 r576 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-201 3GeoLabs SARL4 * Copyright (c) 2009-2015 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 399 399 } 400 400 } 401 errno = NULL;401 errno = ZOO_LOCK_ACQUIRE_FAILED; 402 402 if (!ready) { 403 403 #ifdef DEBUG … … 428 428 int lockShm(int id){ 429 429 struct sembuf sb; 430 int i;431 430 sb.sem_num = 0; 432 431 sb.sem_op = -1; /* set to allocate resource */ … … 629 628 630 629 char *zCapitalize1(char *tmp){ 631 char *res=strdup(tmp);632 633 634 630 char *res=zStrdup(tmp); 631 if(res[0]>=97 && res[0]<=122) 632 res[0]-=32; 633 return res; 635 634 } 636 635 637 636 char *zCapitalize(char *tmp){ 638 637 int i=0; 639 char *res= strdup(tmp);638 char *res=zStrdup(tmp); 640 639 for(i=0;i<strlen(res);i++) 641 640 if(res[i]>=97 && res[i]<=122) … … 713 712 714 713 714 /************************************************************************/ 715 /* soapEnvelope() */ 716 /************************************************************************/ 717 718 /** 719 * Generate a SOAP Envelope node when required (if the isSoap key of the [main] 720 * section is set to true). 721 * 722 * @param conf the conf maps containing the main.cfg settings 723 * @param n the node used as children of the generated soap:Envelope 724 * @return the generated soap:Envelope (if isSoap=true) or the input node n 725 * (when isSoap=false) 726 */ 715 727 xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){ 716 728 map* soap=getMapFromMaps(conf,"main","isSoap"); … … 737 749 } 738 750 739 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,const char* service,maps* m){ 740 741 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; 751 /************************************************************************/ 752 /* printWPSHeader() */ 753 /************************************************************************/ 754 755 /** 756 * Generate a WPS header. 757 * 758 * @param doc the document to add the header 759 * @param m the conf maps containing the main.cfg settings 760 * @param req the request type (GetCapabilities,DescribeProcess,Execute) 761 * @param rname the root node name 762 * @return the generated wps:rname xmlNodePtr (can be wps: Capabilities, 763 * wps:ProcessDescriptions,wps:ExecuteResponse) 764 */ 765 xmlNodePtr printWPSHeader(xmlDocPtr doc,maps* m,const char* req,const char* rname){ 766 767 xmlNsPtr ns,ns_xsi; 768 xmlNodePtr n; 769 770 int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); 771 ns=usedNs[wpsId]; 772 n = xmlNewNode(ns, BAD_CAST rname); 773 zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 774 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 775 zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 776 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 777 ns_xsi=usedNs[xsiId]; 778 779 char *tmp=(char*) malloc((86+strlen(req)+1)*sizeof(char)); 780 sprintf(tmp,"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wps%s_response.xsd",req); 781 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp); 782 free(tmp); 783 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 784 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 785 addLangAttr(n,m); 786 xmlNodePtr fn=soapEnvelope(m,n); 787 xmlDocSetRootElement(doc, fn); 788 return n; 789 } 790 791 /************************************************************************/ 792 /* printGetCapabilitiesHeader() */ 793 /************************************************************************/ 794 795 /** 796 * Generate a Capabilities header. 797 * 798 * @param doc the document to add the header 799 * @param m the conf maps containing the main.cfg settings 800 * @return the generated wps:ProcessOfferings xmlNodePtr 801 */ 802 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,maps* m){ 803 804 xmlNsPtr ns,ns_ows,ns_xlink; 742 805 xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6; 743 /** 744 * Create the document and its temporary root. 745 */ 806 n = printWPSHeader(doc,m,"GetCapabilities","Capabilities"); 807 maps* toto1=getMaps(m,"main"); 808 char tmp[256]; 809 746 810 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 747 811 ns=usedNs[wpsId]; 748 maps* toto1=getMaps(m,"main"); 749 750 n = xmlNewNode(ns, BAD_CAST "Capabilities"); 751 int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 812 int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); 813 ns_xlink=usedNs[xlinkId]; 814 int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 752 815 ns_ows=usedNs[owsId]; 753 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 754 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 755 ns_xsi=usedNs[xsiId]; 756 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 757 ns_xlink=usedNs[xlinkId]; 758 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd"); 759 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 760 addLangAttr(n,m); 761 762 if(toto1!=NULL){ 763 map* tmp=getMap(toto1->content,"version"); 764 if(tmp!=NULL){ 765 xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value); 766 } 767 else 768 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 769 } 770 else 771 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 772 773 char tmp[256]; 774 816 775 817 nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); 776 818 maps* tmp4=getMaps(m,"identification"); … … 827 869 nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); 828 870 xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); 829 xmlAddChild(nc,nc2); 871 xmlAddChild(nc,nc2); 830 872 } 831 873 tmp2=tmp2->next; … … 972 1014 } 973 1015 else 974 SERVICE_URL = strdup("not_ found");1016 SERVICE_URL = strdup("not_defined"); 975 1017 } 976 1018 else 977 SERVICE_URL = strdup("not_ found");1019 SERVICE_URL = strdup("not_defined"); 978 1020 979 1021 for(j=0;j<3;j++){ … … 983 1025 nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); 984 1026 nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); 985 sprintf(tmp,"%s /%s",SERVICE_URL,service);1027 sprintf(tmp,"%s",SERVICE_URL); 986 1028 xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); 987 1029 xmlAddChild(nc3,nc4); 988 if(j>0){ 989 nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); 990 xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); 991 xmlAddChild(nc3,nc4); 992 } 1030 nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); 1031 xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); 1032 xmlAddChild(nc3,nc4); 993 1033 xmlAddChild(nc2,nc3); 994 1034 xmlAddChild(nc1,nc2); … … 1045 1085 xmlAddChild(n,nc1); 1046 1086 1047 xmlNodePtr fn=soapEnvelope(m,n);1048 xmlDocSetRootElement(doc, fn);1049 //xmlFreeNs(ns);1050 1087 free(SERVICE_URL); 1051 1088 return nc; 1052 1089 } 1090 1053 1091 1054 1092 void addPrefix(maps* conf,map* level,service* serv){ … … 1115 1153 xmlAddChild(nc,nc1); 1116 1154 } 1117 }1118 1119 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){1120 1121 xmlNsPtr ns,ns_xsi;1122 xmlNodePtr n;1123 1124 int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");1125 ns=usedNs[wpsId];1126 n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");1127 zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");1128 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");1129 zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");1130 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");1131 ns_xsi=usedNs[xsiId];1132 1133 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd");1134 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");1135 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");1136 addLangAttr(n,m);1137 1138 xmlNodePtr fn=soapEnvelope(m,n);1139 xmlDocSetRootElement(doc, fn);1140 1141 return n;1142 1155 } 1143 1156 … … 1668 1681 1669 1682 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1670 xmlNsPtr ns,ns_ows,ns_xlink ,ns_xsi;1683 xmlNsPtr ns,ns_ows,ns_xlink; 1671 1684 xmlNodePtr nr,n,nc,nc1=NULL,nc3; 1672 1685 xmlDocPtr doc; … … 1674 1687 time(&time1); 1675 1688 nr=NULL; 1676 /**1677 * Create the document and its temporary root.1678 */1679 1689 doc = xmlNewDoc(BAD_CAST "1.0"); 1690 n = printWPSHeader(doc,m,"Execute","ExecuteResponse"); 1680 1691 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 1681 1692 ns=usedNs[wpsId]; 1682 1683 n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); 1684 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 1685 int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 1693 int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 1686 1694 ns_ows=usedNs[owsId]; 1687 int xlinkId=zooXmlAddNs( n,"http://www.w3.org/1999/xlink","xlink");1695 int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); 1688 1696 ns_xlink=usedNs[xlinkId]; 1689 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");1690 ns_xsi=usedNs[xsiId];1691 1692 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");1693 1694 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");1695 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");1696 addLangAttr(n,m);1697 1697 1698 1698 char tmp[256]; … … 1876 1876 while(mcursor!=NULL){ 1877 1877 scursor=getElements(serv->outputs,mcursor->name); 1878 printOutputDefinitions 1(doc,nc,ns,ns_ows,scursor,mcursor,"Output");1878 printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); 1879 1879 mcursor=mcursor->next; 1880 1880 } … … 1915 1915 } 1916 1916 1917 #ifdef DEBUG1918 fprintf(stderr,"printProcessResponse 1 202\n");1919 #endif1920 nr=soapEnvelope(m,n);1921 xmlDocSetRootElement(doc, nr);1922 1923 1917 if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED){ 1924 1918 semid lid=getShmLockId(m,1); … … 1936 1930 char tmpMsg[1024]; 1937 1931 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the ExecuteResponse."),stored_path); 1938 map * errormap = createMap("text",tmpMsg); 1939 addToMap(errormap,"code", "InternalError"); 1940 printExceptionReportResponse(m,errormap); 1941 freeMap(&errormap); 1942 free(errormap); 1932 1933 errorException(m,tmpMsg,"InternalError",NULL); 1943 1934 xmlFreeDoc(doc); 1944 1935 xmlCleanupParser(); … … 1995 1986 } 1996 1987 1997 void printOutputDefinitions 1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){1988 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){ 1998 1989 xmlNodePtr nc1; 1999 1990 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 2012 2003 || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 2013 2004 || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) 2014 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);2015 tmp=tmp->next;2016 }2017 tmp=getMap(e->defaults->content,"asReference");2018 if(tmp==NULL)2019 xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");2020 2021 tmp=e->content;2022 2023 printDescription(nc1,ns_ows,m->name,e->content);2024 2025 xmlAddChild(nc,nc1);2026 2027 }2028 2029 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){2030 xmlNodePtr nc1;2031 nc1=xmlNewNode(ns_wps, BAD_CAST type);2032 map *tmp=NULL;2033 if(e!=NULL && e->defaults!=NULL)2034 tmp=e->defaults->content;2035 else{2036 /*2037 dumpElements(e);2038 */2039 return;2040 }2041 while(tmp!=NULL){2042 2005 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); 2043 2006 tmp=tmp->next; … … 2212 2175 if(rs==NULL){ 2213 2176 char tmp1[1024]; 2214 sprintf(tmp1,"% u",strlen(tmp3->value));2177 sprintf(tmp1,"%ld",strlen(tmp3->value)); 2215 2178 rs=createMap("size",tmp1); 2216 2179 isSized=false; … … 2335 2298 } 2336 2299 2300 /************************************************************************/ 2301 /* printExceptionReportResponse() */ 2302 /************************************************************************/ 2303 2304 /** 2305 * Print an OWS ExceptionReport Document and HTTP headers (when required) 2306 * depending on the code. 2307 * Set hasPrinted value to true in the [lenv] section. 2308 * 2309 * @param m the conf maps 2310 * @param s the map containing the text,code,locator keys 2311 */ 2337 2312 void printExceptionReportResponse(maps* m,map* s){ 2338 2313 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) … … 2351 2326 map* tmp=getMap(s,"code"); 2352 2327 if(tmp!=NULL){ 2353 if(strcmp(tmp->value,"OperationNotSupported")==0) 2328 if(strcmp(tmp->value,"OperationNotSupported")==0 || 2329 strcmp(tmp->value,"NoApplicableCode")==0) 2354 2330 exceptionCode="501 Not Implemented"; 2355 2331 else … … 2361 2337 exceptionCode="400 Bad request"; 2362 2338 else 2363 if(strcmp(tmp->value,"NoApplicableCode")==0) 2364 exceptionCode="501 Internal Server Error"; 2365 else 2366 exceptionCode="501 Internal Server Error"; 2339 exceptionCode="501 Internal Server Error"; 2367 2340 } 2368 2341 else … … 2397 2370 } 2398 2371 2372 /************************************************************************/ 2373 /* createExceptionReportNode() */ 2374 /************************************************************************/ 2375 2376 /** 2377 * Create an OWS ExceptionReport Node. 2378 * 2379 * @param m the conf maps 2380 * @param s the map containing the text,code,locator keys 2381 * @param use_ns (0/1) choose if you want to generate an ExceptionReport or 2382 * ows:ExceptionReport node respectively 2383 * @return the ExceptionReport/ows:ExceptionReport node 2384 */ 2399 2385 xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ 2400 2386 … … 2404 2390 int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows"); 2405 2391 ns=usedNs[nsid]; 2406 if(use_ns== 1){2392 if(use_ns==0){ 2407 2393 ns=NULL; 2408 2394 } 2409 2395 n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); 2410 2396 if(use_ns==1){ 2411 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1", NULL);2397 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST"ows"); 2412 2398 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 2413 2399 ns_xsi=usedNs[xsiId]; … … 2419 2405 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); 2420 2406 2421 nc = xmlNewNode(ns, BAD_CAST "Exception"); 2422 2423 map* tmp=getMap(s,"code"); 2424 if(tmp!=NULL) 2425 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); 2407 int length=1; 2408 int cnt=0; 2409 map* len=getMap(s,"length"); 2410 if(len!=NULL) 2411 length=atoi(len->value); 2412 fprintf(stderr,"LEN %d %s %d \n",length,__FILE__,__LINE__); 2413 for(cnt=0;cnt<length;cnt++){ 2414 nc = xmlNewNode(ns, BAD_CAST "Exception"); 2415 2416 map* tmp=getMapArray(s,"code",cnt); 2417 if(tmp==NULL) 2418 tmp=getMap(s,"code"); 2419 if(tmp!=NULL) 2420 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); 2421 else 2422 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); 2423 2424 tmp=getMapArray(s,"locator",cnt); 2425 if(tmp==NULL) 2426 tmp=getMap(s,"locator"); 2427 if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0) 2428 xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value); 2429 2430 tmp=getMapArray(s,"text",cnt); 2431 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2432 if(tmp!=NULL){ 2433 xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); 2434 xmlAddChild(nc1,txt); 2435 } 2436 else{ 2437 xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); 2438 } 2439 xmlAddChild(nc,nc1); 2440 xmlAddChild(n,nc); 2441 } 2442 return n; 2443 } 2444 2445 /************************************************************************/ 2446 /* errorException() */ 2447 /************************************************************************/ 2448 2449 /** 2450 * Print an OWS ExceptionReport. 2451 * 2452 * @param m the conf maps 2453 * @param message the error message 2454 * @param errorcode the error code 2455 * @param locator the potential locator 2456 */ 2457 int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 2458 { 2459 map* errormap = createMap("text", message); 2460 addToMap(errormap,"code", errorcode); 2461 if(locator!=NULL) 2462 addToMap(errormap,"locator", locator); 2426 2463 else 2427 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); 2428 2429 tmp=getMap(s,"locator"); 2430 if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0) 2431 xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value); 2432 2433 2434 tmp=getMap(s,"text"); 2435 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2436 if(tmp!=NULL){ 2437 xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); 2438 xmlAddChild(nc1,txt); 2439 } 2440 else{ 2441 xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); 2442 } 2443 xmlAddChild(nc,nc1); 2444 xmlAddChild(n,nc); 2445 return n; 2464 addToMap(errormap,"locator", "NULL"); 2465 printExceptionReportResponse(m,errormap); 2466 freeMap(&errormap); 2467 free(errormap); 2468 return -1; 2446 2469 } 2447 2470 … … 2479 2502 fclose(file); 2480 2503 char rsize[100]; 2481 sprintf(rsize,"% d",count*sizeof(char));2504 sprintf(rsize,"%ld",count*sizeof(char)); 2482 2505 addToMap(tmpMap1,"size",rsize); 2483 2506 } … … 2529 2552 char tmpMsg[1024]; 2530 2553 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the session maps."),session_file_path); 2531 map * errormap = createMap("text",tmpMsg); 2532 addToMap(errormap,"code", "InternalError"); 2533 2534 printExceptionReportResponse(m,errormap); 2535 freeMap(&errormap); 2536 free(errormap); 2554 errorException(m,tmpMsg,"InternalError",NULL); 2555 2537 2556 return; 2538 2557 } … … 2543 2562 } 2544 2563 2545 if(res==SERVICE_FAILED){ 2546 map * errormap; 2547 map *lenv; 2548 lenv=getMapFromMaps(m,"lenv","message"); 2549 char *tmp0; 2550 if(lenv!=NULL){ 2551 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2552 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2553 } 2554 else{ 2555 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2556 sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service.")); 2557 } 2558 errormap = createMap("text",tmp0); 2559 free(tmp0); 2560 addToMap(errormap,"code", "InternalError"); 2561 dumpMap(errormap); 2562 printExceptionReportResponse(m,errormap); 2563 freeMap(&errormap); 2564 free(errormap); 2565 return; 2566 } 2567 2568 2564 if(res==SERVICE_FAILED){ 2565 map *lenv; 2566 lenv=getMapFromMaps(m,"lenv","message"); 2567 char *tmp0; 2568 if(lenv!=NULL){ 2569 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2570 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2571 } 2572 else{ 2573 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2574 sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service.")); 2575 } 2576 errorException(m,tmp0,"InternalError",NULL); 2577 free(tmp0); 2578 return; 2579 } 2580 2581 2582 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2569 2583 if(asRaw==0){ 2570 2584 #ifdef DEBUG … … 2573 2587 #endif 2574 2588 maps* tmpI=request_outputs; 2589 2575 2590 while(tmpI!=NULL){ 2576 2591 #ifdef USE_MS … … 2596 2611 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2597 2612 } 2598 2599 map *tmp1=getMapFromMaps(m,"main","tmpPath");2600 2613 2601 2614 map *gfile=getMap(tmpI->content,"generated_file"); … … 2648 2661 char tmpMsg[1024]; 2649 2662 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name); 2650 map * errormap = createMap("text",tmpMsg); 2651 addToMap(errormap,"code", "InternalError"); 2652 printExceptionReportResponse(m,errormap); 2653 freeMap(&errormap); 2654 free(errormap); 2663 errorException(m,tmpMsg,"InternalError",NULL); 2655 2664 free(file_name); 2656 2665 free(file_path); … … 2730 2739 map *gfile=getMap(tmpI->content,"generated_file"); 2731 2740 if(gfile!=NULL){ 2741 gfile=getMap(tmpI->content,"expected_generated_file"); 2742 if(gfile==NULL){ 2743 gfile=getMap(tmpI->content,"generated_file"); 2744 } 2732 2745 readGeneratedFile(m,tmpI->content,gfile->value); 2733 2746 } … … 2736 2749 char tmpMsg[1024]; 2737 2750 sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name); 2738 map * errormap = createMap("text",tmpMsg); 2739 addToMap(errormap,"code", "InvalidParameterValue"); 2740 printExceptionReportResponse(m,errormap); 2741 freeMap(&errormap); 2742 free(errormap); 2751 errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput"); 2743 2752 return; 2744 2753 } … … 2842 2851 } 2843 2852 2844 char* addDefaultValues(maps** out,elements* in,maps* m,int type){ 2853 char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){ 2854 map *res=*err; 2845 2855 elements* tmpInputs=in; 2846 2856 maps* out1=*out; 2857 char *result=NULL; 2858 int nb=0; 2847 2859 if(type==1){ 2848 2860 while(out1!=NULL){ 2849 if(getElements(in,out1->name)==NULL) 2850 return out1->name; 2861 if(getElements(in,out1->name)==NULL){ 2862 if(res==NULL){ 2863 res=createMap("value",out1->name); 2864 }else{ 2865 setMapArray(res,"value",nb,out1->name); 2866 } 2867 nb++; 2868 result=out1->name; 2869 } 2851 2870 out1=out1->next; 2871 } 2872 if(res!=NULL){ 2873 *err=res; 2874 return result; 2852 2875 } 2853 2876 out1=*out; … … 2867 2890 freeMaps(&tmpMaps2); 2868 2891 free(tmpMaps2); 2869 return tmpInputs->name; 2892 if(res==NULL){ 2893 res=createMap("value",tmpInputs->name); 2894 }else{ 2895 setMapArray(res,"value",nb,tmpInputs->name); 2896 } 2897 nb++; 2898 result=tmpInputs->name; 2870 2899 } 2871 2900 else{ … … 2876 2905 } 2877 2906 } 2878 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 2879 if(tmpMaxO!=NULL){ 2880 if(tmpMaps2->content==NULL) 2881 tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); 2882 else 2883 addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); 2884 } 2885 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 2886 if(tmpMaxMB!=NULL){ 2887 if(tmpMaps2->content==NULL) 2888 tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value); 2889 else 2890 addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value); 2891 } 2892 } 2893 2894 iotype* tmpIoType=tmpInputs->defaults; 2895 if(tmpIoType!=NULL){ 2896 map* tmpm=tmpIoType->content; 2897 while(tmpm!=NULL){ 2898 if(tmpMaps2->content==NULL) 2899 tmpMaps2->content=createMap(tmpm->name,tmpm->value); 2900 else 2901 addToMap(tmpMaps2->content,tmpm->name,tmpm->value); 2902 tmpm=tmpm->next; 2903 } 2904 } 2905 addToMap(tmpMaps2->content,"inRequest","false"); 2906 if(type==0){ 2907 map *tmpMap=getMap(tmpMaps2->content,"value"); 2908 if(tmpMap==NULL) 2909 addToMap(tmpMaps2->content,"value","NULL"); 2910 } 2911 if(out1==NULL){ 2912 *out=dupMaps(&tmpMaps2); 2913 out1=*out; 2914 } 2915 else 2916 addMapsToMaps(&out1,tmpMaps2); 2917 freeMap(&tmpMaps2->content); 2918 free(tmpMaps2->content); 2919 tmpMaps2->content=NULL; 2920 freeMaps(&tmpMaps2); 2921 free(tmpMaps2); 2922 tmpMaps2=NULL; 2907 if(res==NULL){ 2908 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 2909 if(tmpMaxO!=NULL){ 2910 if(tmpMaps2->content==NULL) 2911 tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); 2912 else 2913 addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); 2914 } 2915 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 2916 if(tmpMaxMB!=NULL){ 2917 if(tmpMaps2->content==NULL) 2918 tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value); 2919 else 2920 addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value); 2921 } 2922 } 2923 } 2924 2925 if(res==NULL){ 2926 iotype* tmpIoType=tmpInputs->defaults; 2927 if(tmpIoType!=NULL){ 2928 map* tmpm=tmpIoType->content; 2929 while(tmpm!=NULL){ 2930 if(tmpMaps2->content==NULL) 2931 tmpMaps2->content=createMap(tmpm->name,tmpm->value); 2932 else 2933 addToMap(tmpMaps2->content,tmpm->name,tmpm->value); 2934 tmpm=tmpm->next; 2935 } 2936 } 2937 addToMap(tmpMaps2->content,"inRequest","false"); 2938 if(type==0){ 2939 map *tmpMap=getMap(tmpMaps2->content,"value"); 2940 if(tmpMap==NULL) 2941 addToMap(tmpMaps2->content,"value","NULL"); 2942 } 2943 if(out1==NULL){ 2944 *out=dupMaps(&tmpMaps2); 2945 out1=*out; 2946 } 2947 else 2948 addMapsToMaps(&out1,tmpMaps2); 2949 freeMap(&tmpMaps2->content); 2950 free(tmpMaps2->content); 2951 tmpMaps2->content=NULL; 2952 freeMaps(&tmpMaps2); 2953 free(tmpMaps2); 2954 tmpMaps2=NULL; 2955 } 2923 2956 } 2924 2957 else{ … … 3048 3081 } 3049 3082 tmpInputs=tmpInputs->next; 3083 } 3084 if(res!=NULL){ 3085 *err=res; 3086 return result; 3050 3087 } 3051 3088 return ""; … … 3381 3418 3382 3419 } 3420 return 0; 3383 3421 } 3384 3422 … … 3480 3518 } 3481 3519 3482 int errorException(maps *m, const char *message, const char *errorcode, const char *locator)3483 {3484 map* errormap = createMap("text", message);3485 addToMap(errormap,"code", errorcode);3486 if(locator!=NULL)3487 addToMap(errormap,"locator", locator);3488 else3489 addToMap(errormap,"locator", "NULL");3490 printExceptionReportResponse(m,errormap);3491 freeMap(&errormap);3492 free(errormap);3493 return -1;3494 }3495 3496 3497 3520 char *readVSIFile(maps* conf,const char* dataSource){ 3498 3521 VSILFILE * fichier=VSIFOpenL(dataSource,"rb"); … … 3501 3524 if(fichier==NULL){ 3502 3525 char tmp[1024]; 3503 sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty % d.",3526 sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %lld.", 3504 3527 dataSource,file_status.st_size); 3505 3528 setMapInMaps(conf,"lenv","message",tmp); … … 3620 3643 return 0; 3621 3644 } 3645 3646 /************************************************************************/ 3647 /* checkValidValue() */ 3648 /************************************************************************/ 3649 3650 /** 3651 * Verify if a parameter value is valid. 3652 * 3653 * @param request the request map 3654 * @param res the error map potentially generated 3655 * @param avalues the acceptable values (or null if testing only for presence) 3656 * @param mandatory verify the presence of the parameter if mandatory > 0 3657 */ 3658 void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){ 3659 map* lres=*res; 3660 map* r_inputs = getMap (request,toCheck); 3661 if (r_inputs == NULL){ 3662 if(mandatory>0){ 3663 char *replace=_("Mandatory parameter <%s> was not specified"); 3664 char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char)); 3665 sprintf(message,replace,toCheck); 3666 if(lres==NULL){ 3667 lres=createMap("code","MissingParameterValue"); 3668 addToMap(lres,"text",message); 3669 addToMap(lres,"locator",toCheck); 3670 }else{ 3671 int length=1; 3672 map* len=getMap(lres,"length"); 3673 if(len!=NULL){ 3674 length=atoi(len->value); 3675 } 3676 setMapArray(lres,"text",length,message); 3677 setMapArray(lres,"locator",length,toCheck); 3678 setMapArray(lres,"code",length,"MissingParameter"); 3679 } 3680 free(message); 3681 } 3682 }else{ 3683 if(avalues==NULL) 3684 return; 3685 int nb=0; 3686 int hasValidValue=-1; 3687 while(avalues[nb]!=NULL){ 3688 if(strcasecmp(avalues[nb],r_inputs->value)==0){ 3689 hasValidValue=1; 3690 break; 3691 } 3692 nb++; 3693 } 3694 if(hasValidValue<0){ 3695 char *replace=_("Ununderstood <%s> value, %s %s the only acceptable value."); 3696 nb=0; 3697 char *vvalues=NULL; 3698 char* num=_("is"); 3699 while(avalues[nb]!=NULL){ 3700 char *tvalues; 3701 if(vvalues==NULL){ 3702 vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char)); 3703 sprintf(vvalues,"%s",avalues[nb]); 3704 } 3705 else{ 3706 tvalues=zStrdup(vvalues); 3707 vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char)); 3708 sprintf(vvalues,"%s, %s",tvalues,avalues[nb]); 3709 free(tvalues); 3710 num=_("are"); 3711 } 3712 nb++; 3713 } 3714 char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char)); 3715 sprintf(message,replace,toCheck,vvalues,num); 3716 if(lres==NULL){ 3717 lres=createMap("code","InvalidParameterValue"); 3718 addToMap(lres,"text",message); 3719 addToMap(lres,"locator",toCheck); 3720 }else{ 3721 int length=1; 3722 map* len=getMap(lres,"length"); 3723 if(len!=NULL){ 3724 length=atoi(len->value); 3725 } 3726 setMapArray(lres,"text",length,message); 3727 setMapArray(lres,"locator",length,toCheck); 3728 setMapArray(lres,"code",length,"InvalidParameterValue"); 3729 } 3730 } 3731 } 3732 if(lres!=NULL){ 3733 *res=lres; 3734 } 3735 }
Note: See TracChangeset
for help on using the changeset viewer.