Changeset 967 for trunk/zoo-project/zoo-kernel/response_print.c
- Timestamp:
- Dec 18, 2020, 2:13:22 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/response_print.c
r966 r967 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2009-20 15GeoLabs SARL4 * Copyright (c) 2009-2020 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 41 41 42 42 #include "mimetypes.h" 43 #include "service_json.h" 43 44 44 45 /** 45 46 * Add prefix to the service name. 46 47 * 47 * @param conf the conf maps containing the main.cfg settings48 * @param level the map containing the level information49 * @param servthe service structure created from the zcfg file50 */ 51 void addPrefix(maps* conf,map* level,service* serv){52 if( level!=NULL){53 char key[25];54 char* p refix=NULL;55 int clevel=atoi(level->value);56 int cl=0;57 for( cl=0;cl<clevel;cl++){58 sprintf( key,"sprefix_%d",cl);59 map* tmp2=getMapFromMaps( conf,"lenv",key);48 * @param pmsConf the conf maps containing the main.cfg settings 49 * @param pmLevel the map containing the level information 50 * @param psService the service structure created from the zcfg file 51 */ 52 void addPrefix(maps* pmsConf,map* pmLevel,service* psService){ 53 if(pmLevel!=NULL){ 54 char acKey[25]; 55 char* pcaPrefix=NULL; 56 int iClevel=atoi(pmLevel->value); 57 int iCl=0; 58 for(iCl=0;iCl<iClevel;iCl++){ 59 sprintf(acKey,"sprefix_%d",iCl); 60 map* tmp2=getMapFromMaps(pmsConf,"lenv",acKey); 60 61 if(tmp2!=NULL){ 61 if(p refix==NULL)62 p refix=zStrdup(tmp2->value);62 if(pcaPrefix==NULL) 63 pcaPrefix=zStrdup(tmp2->value); 63 64 else{ 64 int plen=strlen(p refix);65 p refix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));66 memcpy(p refix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));67 p refix[plen+strlen(tmp2->value)]=0;68 } 69 } 70 } 71 if(p refix!=NULL){72 char* tmp0=zStrdup(serv->name);73 free( serv->name);74 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));75 sprintf( serv->name,"%s%s",prefix,tmp0);76 free( tmp0);77 free(p refix);78 p refix=NULL;65 int plen=strlen(pcaPrefix); 66 pcaPrefix=(char*)realloc(pcaPrefix,(plen+strlen(tmp2->value)+2)*sizeof(char)); 67 memcpy(pcaPrefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char)); 68 pcaPrefix[plen+strlen(tmp2->value)]=0; 69 } 70 } 71 } 72 if(pcaPrefix!=NULL){ 73 char* pcaTmp=zStrdup(psService->name); 74 free(psService->name); 75 psService->name=(char*)malloc((strlen(pcaPrefix)+strlen(pcaTmp)+1)*sizeof(char)); 76 sprintf(psService->name,"%s%s",pcaPrefix,pcaTmp); 77 free(pcaTmp); 78 free(pcaPrefix); 79 pcaPrefix=NULL; 79 80 } 80 81 } … … 84 85 * Print the HTTP headers based on a map. 85 86 * 86 * @param mthe map containing the headers information87 */ 88 void printHeaders(maps* m){89 maps * _tmp=getMaps(m,"headers");90 if( _tmp!=NULL){91 map* _tmp1=_tmp->content;92 while( _tmp1!=NULL){93 printf("%s: %s\r\n", _tmp1->name,_tmp1->value);94 _tmp1=_tmp1->next;95 } 96 } 97 printSessionHeaders( m);87 * @param pmsConf the map containing the headers information 88 */ 89 void printHeaders(maps* pmsConf){ 90 maps *pmsTmp=getMaps(pmsConf,"headers"); 91 if(pmsTmp!=NULL){ 92 map* pmTmp=pmsTmp->content; 93 while(pmTmp!=NULL){ 94 printf("%s: %s\r\n",pmTmp->name,pmTmp->value); 95 pmTmp=pmTmp->next; 96 } 97 } 98 printSessionHeaders(pmsConf); 98 99 } 99 100 … … 104 105 * The session file (sess_<SESSID>_.cfg where <SESSID> is the cookie value) is 105 106 * stored in the conf["main"]["tmpPath"] directory. 106 * @param m the main configuration map 107 */ 108 void printSessionHeaders(maps* m){ 109 maps* tmpSess=getMaps(m,"senv"); 110 if(tmpSess!=NULL){ 111 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 112 maps *tmps=getMaps(m,"senv"); 107 * @param pmsConf the main configuration map 108 */ 109 void printSessionHeaders(maps* pmsConf){ 110 maps* pmsSess=getMaps(pmsConf,"senv"); 111 if(pmsSess!=NULL){ 112 map *pmTmp=getMapFromMaps(pmsConf,"lenv","cookie"); 113 113 char* sessId=NULL; 114 if( _tmp!=NULL){115 printf("Set-Cookie: %s; HttpOnly\r\n", _tmp->value);116 map * _tmp1=getMapFromMaps(m,"senv","ecookie_length");117 if( _tmp1!=NULL){118 int len=atoi( _tmp1->value);114 if(pmTmp!=NULL){ 115 printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp->value); 116 map *pmTmp1=getMapFromMaps(pmsConf,"senv","ecookie_length"); 117 if(pmTmp1!=NULL){ 118 int len=atoi(pmTmp1->value); 119 119 int cnt=0; 120 120 for(cnt=0;cnt<len;cnt++){ 121 map* _tmp2=getMapArray(tmps->content,"ecookie",cnt);122 if( _tmp2!=NULL)123 printf("Set-Cookie: %s; HttpOnly\r\n", _tmp2->value);121 map* pmTmp2=getMapArray(pmsSess->content,"ecookie",cnt); 122 if(pmTmp2!=NULL) 123 printf("Set-Cookie: %s; HttpOnly\r\n",pmTmp2->value); 124 124 } 125 125 } 126 126 printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 127 127 char session_file_path[100]; 128 char *tmp1=strtok( _tmp->value,";");128 char *tmp1=strtok(pmTmp->value,";"); 129 129 if(tmp1!=NULL) 130 130 sprintf(session_file_path,"%s",strstr(tmp1,"=")+1); 131 131 else 132 sprintf(session_file_path,"%s",strstr( _tmp->value,"=")+1);132 sprintf(session_file_path,"%s",strstr(pmTmp->value,"=")+1); 133 133 sessId=zStrdup(session_file_path); 134 134 }else{ 135 maps* t=getMaps( m,"senv");135 maps* t=getMaps(pmsConf,"senv"); 136 136 map*p=t->content; 137 137 while(p!=NULL){ … … 144 144 } 145 145 char session_file_path[1024]; 146 map *tmpPath=getMapFromMaps( m,"main","sessPath");146 map *tmpPath=getMapFromMaps(pmsConf,"main","sessPath"); 147 147 if(tmpPath==NULL) 148 tmpPath=getMapFromMaps( m,"main","tmpPath");148 tmpPath=getMapFromMaps(pmsConf,"main","tmpPath"); 149 149 sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId); 150 150 FILE* teste=fopen(session_file_path,"w"); … … 152 152 char tmpMsg[1024]; 153 153 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path); 154 errorException( m,tmpMsg,"InternalError",NULL);154 errorException(pmsConf,tmpMsg,"InternalError",NULL); 155 155 return; 156 156 } 157 157 else{ 158 158 fclose(teste); 159 dumpMapsToFile( tmpSess,session_file_path,1);159 dumpMapsToFile(pmsSess,session_file_path,1); 160 160 } 161 161 } … … 2096 2096 if(vid==0) 2097 2097 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 2098 else 2098 else 2099 2099 printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid); 2100 2100 } … … 2535 2535 2536 2536 /** 2537 * Produce the status string used in HTTP headers. 2538 * 2539 * @param pmConf the maps containing the settings of the main.cfg file 2540 * @param pmCode the map containing the error code (or a map array of the same keys) 2541 */ 2542 const char* produceStatusString(maps* pmConf,map* pmCode){ 2543 if(pmCode!=NULL){ 2544 int iI=0; 2545 for(iI=0;iI<3;iI++){ 2546 int iJ=0; 2547 for(iJ=0;;iJ++){ 2548 if(aapccStatusCodes[iI][iJ]==NULL) 2549 break; 2550 else{ 2551 if(strcmp(aapccStatusCodes[iI][iJ],pmCode->value)==0) 2552 return aapccStatusCodes[iI][0]; 2553 } 2554 } 2555 } 2556 } 2557 else{ 2558 return aapccStatusCodes[3][0]; 2559 } 2560 } 2561 2562 /** 2537 2563 * Print an OWS ExceptionReport Document and HTTP headers (when required) 2538 2564 * depending on the code. … … 2542 2568 * @param s the map containing the text,code,locator keys (or a map array of the same keys) 2543 2569 */ 2544 void printExceptionReportResponse(maps* m,map* s){ 2545 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) 2546 return; 2570 void _printExceptionReportResponse(maps* m,map* s){ 2547 2571 int buffersize; 2548 2572 xmlDocPtr doc; … … 2557 2581 2558 2582 map* tmp=getMap(s,"code"); 2559 if(tmp!=NULL){ 2560 if(strcmp(tmp->value,"OperationNotSupported")==0 || 2561 strcmp(tmp->value,"NoApplicableCode")==0) 2562 exceptionCode="501 Not Implemented"; 2563 else 2564 if(strcmp(tmp->value,"MissingParameterValue")==0 || 2565 strcmp(tmp->value,"InvalidUpdateSequence")==0 || 2566 strcmp(tmp->value,"OptionNotSupported")==0 || 2567 strcmp(tmp->value,"VersionNegotiationFailed")==0 || 2568 strcmp(tmp->value,"InvalidParameterValue")==0) 2569 exceptionCode="400 Bad request"; 2570 else 2571 exceptionCode="501 Internal Server Error"; 2572 } 2573 else 2574 exceptionCode="501 Internal Server Error"; 2583 exceptionCode=produceStatusString(m,tmp); 2575 2584 tmp=getMapFromMaps(m,"lenv","status_code"); 2576 2585 if(tmp!=NULL) … … 2601 2610 zooXmlCleanupNs(); 2602 2611 if(m!=NULL) 2603 setMapInMaps(m,"lenv","hasPrinted","true"); 2612 setMapInMaps(m,"lenv","hasPrinted","true"); 2613 } 2614 2615 /** 2616 * Print an OWS ExceptionReport or exception.yaml Document and HTTP headers 2617 * (when required) depending on the code. 2618 * 2619 * @param pmsConf the maps containing the settings of the main.cfg file 2620 * @param psService the service 2621 */ 2622 void printExceptionReportResponse(maps* pmsConf,map* psService){ 2623 if(getMapFromMaps(pmsConf,"lenv","hasPrinted")!=NULL) 2624 return; 2625 map* pmExecutionType=getMapFromMaps(pmsConf,"main","executionType"); 2626 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0) 2627 _printExceptionReportResponse(pmsConf,psService); 2628 else 2629 printExceptionReportResponseJ(pmsConf,psService); 2604 2630 } 2605 2631 … … 2694 2720 int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 2695 2721 { 2722 map* pmExectionType=getMapFromMaps(m,"main","executionType"); 2696 2723 map* errormap = createMap("text", message); 2697 2724 addToMap(errormap,"code", errorcode); … … 2700 2727 else 2701 2728 addToMap(errormap,"locator", "NULL"); 2702 printExceptionReportResponse(m,errormap); 2729 if(pmExectionType!=NULL && strncasecmp(pmExectionType->value,"xml",3)==0) 2730 printExceptionReportResponse(m,errormap); 2731 else{ 2732 printExceptionReportResponseJ(m,errormap); 2733 setMapInMaps(m,"lenv","no-headers","true"); 2734 } 2703 2735 freeMap(&errormap); 2704 2736 free(errormap); 2705 2737 return -1; 2738 } 2739 2740 /** 2741 * Produce a copy file and the corresponding url in case it is required 2742 * Please, free the returned ressource while used 2743 * 2744 * @param pmConf maps* pointing to the main configuration file 2745 */ 2746 char* produceFileUrl(service* psService,maps* pmsConf,maps* pmsOutputs,const char* pccFormat, int itn){ 2747 // Create file for reference data if not existing 2748 map *pmGFile=getMap(pmsOutputs->content,"generated_file"); 2749 map *pmTmpPath=getMapFromMaps(pmsConf,"main","tmpPath"); 2750 map *pmTmpUrl=getMapFromMaps(pmsConf,"main","tmpUrl"); 2751 char *pcaFileName=NULL; 2752 char *pcaFilePath=NULL; 2753 char *pcaFileUrl=NULL; 2754 if(pmGFile!=NULL){ 2755 pmGFile=getMap(pmsOutputs->content,"expected_generated_file"); 2756 if(pmGFile==NULL){ 2757 pmGFile=getMap(pmsOutputs->content,"generated_file"); 2758 } 2759 if(strstr(pmGFile->value,pmTmpPath->value)!=NULL) 2760 pcaFileName=zStrdup(strstr(pmGFile->value,pmTmpPath->value)+strlen(pmTmpPath->value)); 2761 } 2762 // Create file for reference data 2763 map *pmUsid=getMapFromMaps(pmsConf,"lenv","usid"); 2764 map *pmExt=getMap(pmsOutputs->content,"extension"); 2765 if(pmGFile==NULL){ 2766 char acFileExt[32]; 2767 if( pmExt != NULL && pmExt->value != NULL) { 2768 strncpy(acFileExt, pmExt->value, 32); 2769 } 2770 else { 2771 // Obtain default file extension (see mimetypes.h). 2772 // If the MIME type is not recognized, txt is used as the default extension 2773 map* pmType=getMap(pmsOutputs->content,"mimeType"); 2774 getFileExtension(pmType != NULL ? pmType->value : NULL, acFileExt, 32); 2775 } 2776 if(pcaFileName!=NULL) 2777 free(pcaFileName); 2778 2779 pcaFileName=(char*)malloc((strlen(psService->name)+strlen(pmUsid->value)+strlen(acFileExt)+strlen(pmsOutputs->name)+45)*sizeof(char)); 2780 sprintf(pcaFileName,"ZOO_DATA_%s_%s_%s_%d.%s",psService->name,pmsOutputs->name,pmUsid->value,itn,acFileExt); 2781 2782 pcaFilePath=(char*)malloc((strlen(pmTmpPath->value)+strlen(pcaFileName)+2)*sizeof(char)); 2783 sprintf(pcaFilePath,"%s/%s",pmTmpPath->value,pcaFileName); 2784 }else{ 2785 pcaFilePath=(char*)malloc((strlen(pmGFile->value)+1)*sizeof(char)); 2786 sprintf(pcaFilePath,"%s",pmGFile->value); 2787 } 2788 2789 pcaFileUrl=(char*)malloc((strlen(pmTmpUrl->value)+ 2790 strlen(pcaFileName)+2)*sizeof(char)); 2791 sprintf(pcaFileUrl,"%s/%s",pmTmpUrl->value,pcaFileName); 2792 2793 if(pmGFile==NULL) { 2794 FILE *pfOfile=fopen(pcaFilePath,"wb"); 2795 if(pfOfile==NULL){ 2796 char acTmpMsg[1024]; 2797 sprintf(acTmpMsg, 2798 _("Unable to create the file \"%s\" for storing the %s final result."), 2799 pcaFileName,pmsOutputs->name); 2800 map* pmError=createMap("code","InternalError"); 2801 addToMap(pmError,"message",acTmpMsg); 2802 printExceptionReportResponseJ(pmsConf,pmError); 2803 free(pcaFileName); 2804 free(pcaFilePath); 2805 return NULL; 2806 } 2807 2808 map* pmValue=getMap(pmsOutputs->content,"value"); 2809 if(pmValue==NULL){ 2810 char acTmpMsg[1024]; 2811 sprintf(acTmpMsg, 2812 _("No value found for the requested output %s."), 2813 pmsOutputs->name); 2814 map* pmError=createMap("code","InternalError"); 2815 addToMap(pmError,"message",acTmpMsg); 2816 printExceptionReportResponseJ(pmsConf,pmError); 2817 fclose(pfOfile); 2818 free(pcaFileName); 2819 free(pcaFilePath); 2820 return NULL; 2821 } 2822 if(pccFormat==NULL || strcasecmp(pccFormat,"BoundingBoxData")!=0){ 2823 map* size=getMap(pmsOutputs->content,"size"); 2824 if(size!=NULL && pmValue!=NULL) 2825 fwrite(pmValue->value,1,(atoi(size->value))*sizeof(char),pfOfile); 2826 else 2827 if(pmValue!=NULL && pmValue->value!=NULL) 2828 fwrite(pmValue->value,1, 2829 strlen(pmValue->value)*sizeof(char),pfOfile); 2830 }else 2831 printBoundingBoxDocument(pmsConf,pmsOutputs,pfOfile); 2832 fclose(pfOfile); 2833 } 2834 free(pcaFileName); 2835 free(pcaFilePath); 2836 return pcaFileUrl; 2706 2837 } 2707 2838 … … 2724 2855 fprintf(stderr,"printProcessResponse\n"); 2725 2856 #endif 2726 map* toto=getMap(request_inputs1,"RawDataOutput");2857 map* pmRawData=getMap(request_inputs1,"RawDataOutput"); 2727 2858 int asRaw=0; 2728 if( toto!=NULL)2859 if(pmRawData!=NULL) 2729 2860 asRaw=1; 2730 2861 map* version=getMapFromMaps(m,"main","rversion"); … … 2776 2907 map* testMap=getMap(tmpI->content,"useMapserver"); 2777 2908 #endif 2778 map *gfile=getMap(tmpI->content,"generated_file");2909 /*map *gfile=getMap(tmpI->content,"generated_file"); 2779 2910 char *file_name=NULL; 2780 2911 if(gfile!=NULL){ … … 2785 2916 readGeneratedFile(m,tmpI->content,gfile->value); 2786 2917 file_name=zStrdup((gfile->value)+strlen(tmp1->value)); 2787 } 2788 toto=getMap(tmpI->content,"asReference"); 2918 }*/ 2919 char *pcaFileUrl=NULL; 2920 pmRawData=getMap(tmpI->content,"asReference"); 2789 2921 #ifdef USE_MS 2790 2922 map* geodatatype=getMap(tmpI->content,"geodatatype"); 2791 if( toto!=NULL && strcasecmp(toto->value,"true")==0 &&2923 if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0 && 2792 2924 (testMap==NULL || 2793 2925 strncasecmp(testMap->value,"true",4)!=0 || 2794 2926 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 2795 2927 #else 2796 if( toto!=NULL && strcasecmp(toto->value,"true")==0)2928 if(pmRawData!=NULL && strcasecmp(pmRawData->value,"true")==0) 2797 2929 #endif 2798 2930 { … … 2811 2943 addToMap(tmpI->content,"encoding","UTF-8"); 2812 2944 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2813 }2814 char *file_path=NULL;2815 if(gfile==NULL) {2816 map *ext=getMap(tmpI->content,"extension");2817 char file_ext[32];2818 2819 if( ext != NULL && ext->value != NULL) {2820 strncpy(file_ext, ext->value, 32);2821 }2822 else {2823 // Obtain default file extension (see mimetypes.h).2824 // If the MIME type is not recognized, txt is used as the default extension2825 map* mtype=getMap(tmpI->content,"mimeType");2826 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);2827 }2828 if(file_name!=NULL)2829 free(file_name);2830 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));2831 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);2832 itn++;2833 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));2834 sprintf(file_path,"%s/%s",tmp1->value,file_name);2835 2836 FILE *ofile=fopen(file_path,"wb");2837 if(ofile==NULL){2838 char tmpMsg[1024];2839 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);2840 errorException(m,tmpMsg,"InternalError",NULL);2841 free(file_name);2842 free(file_path);2843 return;2844 }2845 2846 toto=getMap(tmpI->content,"value");2847 if(toto==NULL){2848 char tmpMsg[1024];2849 sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);2850 errorException(m,tmpMsg,"InternalError",NULL);2851 fclose(ofile);2852 free(file_name);2853 free(file_path);2854 return;2855 }2856 if(strcasecmp(format,"BoundingBoxData")!=0){2857 map* size=getMap(tmpI->content,"size");2858 if(size!=NULL && toto!=NULL)2859 fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);2860 else2861 if(toto!=NULL && toto->value!=NULL)2862 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);2863 }else{2864 printBoundingBoxDocument(m,tmpI,ofile);2865 }2866 fclose(ofile);2867 2945 } 2868 2869 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2870 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2871 char *file_url=NULL; 2872 if(strncasecmp(tmp2->value,"http://",7)==0 || 2873 strncasecmp(tmp2->value,"https://",8)==0){ 2874 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2875 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2876 }else{ 2877 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2878 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2879 } 2880 addToMap(tmpI->content,"Reference",file_url); 2881 if(file_name!=NULL) 2882 free(file_name); 2883 if(file_url!=NULL) 2884 free(file_url); 2885 file_name=NULL; 2946 pcaFileUrl=produceFileUrl(s,m,tmpI,format,itn); 2947 itn++; 2948 if(pcaFileUrl==NULL) 2949 return; 2950 addToMap(tmpI->content,"Reference",pcaFileUrl); 2886 2951 } 2887 2952 #ifdef USE_MS … … 2901 2966 } 2902 2967 #endif 2903 if( file_name!=NULL){2904 free( file_name);2905 file_name=NULL;2968 if(pcaFileUrl!=NULL){ 2969 free(pcaFileUrl); 2970 pcaFileUrl=NULL; 2906 2971 } 2907 2972 tmpI=tmpI->next; … … 2947 3012 printBoundingBoxDocument(m,tmpI,NULL); 2948 3013 }else{ 2949 map *gfile=getMap(tmpI->content,"generated_file"); 2950 if(gfile!=NULL){ 2951 gfile=getMap(tmpI->content,"expected_generated_file"); 2952 if(gfile==NULL){ 2953 gfile=getMap(tmpI->content,"generated_file"); 2954 } 2955 readGeneratedFile(m,tmpI->content,gfile->value); 2956 } 2957 toto=getMap(tmpI->content,"value"); 2958 if(toto==NULL){ 2959 char tmpMsg[1024]; 2960 sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name); 2961 errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput"); 2962 return; 2963 } 2964 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2965 if(fname!=NULL) 2966 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2967 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2968 if(rs!=NULL) 2969 printf("Content-Length: %s\r\n",rs->value); 2970 printHeaders(m); 2971 char mime[1024]; 2972 map* mi=getMap(tmpI->content,"mimeType"); 2973 #ifdef DEBUG 2974 fprintf(stderr,"SERVICE OUTPUTS\n"); 2975 dumpMaps(request_outputs); 2976 fprintf(stderr,"SERVICE OUTPUTS\n"); 2977 #endif 2978 map* en=getMap(tmpI->content,"encoding"); 2979 if(mi!=NULL && en!=NULL) 2980 sprintf(mime, 2981 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 2982 mi->value,en->value); 2983 else 2984 if(mi!=NULL) 2985 sprintf(mime, 2986 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2987 mi->value); 2988 else 2989 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2990 printf("%s",mime); 2991 if(rs!=NULL) 2992 fwrite(toto->value,1,atoi(rs->value),stdout); 2993 else 2994 fwrite(toto->value,1,strlen(toto->value),stdout); 2995 #ifdef DEBUG 2996 dumpMap(toto); 2997 #endif 2998 } 2999 } 3014 printRawdataOutput(m,tmpI); 3015 } 3016 } 3017 } 3018 3019 /** 3020 * Print one outputs as raw 3021 * 3022 * @param conf the main configuration maps 3023 * @param outputs the output to be print as raw 3024 */ 3025 void* printRawdataOutput(maps* conf,maps* outputs){ 3026 map *gfile=getMap(outputs->content,"generated_file"); 3027 if(gfile!=NULL){ 3028 gfile=getMap(outputs->content,"expected_generated_file"); 3029 if(gfile==NULL){ 3030 gfile=getMap(outputs->content,"generated_file"); 3031 } 3032 readGeneratedFile(conf,outputs->content,gfile->value); 3033 } 3034 map* toto=getMap(outputs->content,"value"); 3035 if(toto==NULL){ 3036 char tmpMsg[1024]; 3037 sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),outputs->name); 3038 map* pmExecutionType=getMapFromMaps(conf,"main","executionType"); 3039 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0) 3040 errorException(conf,tmpMsg,"InvalidParameterValue","RawDataOutput"); 3041 else{ 3042 setMapInMaps(conf,"lenv","error","true"); 3043 setMapInMaps(conf,"lenv","code","InvalidParameterValue"); 3044 setMapInMaps(conf,"lenv","message",tmpMsg); 3045 } 3046 return NULL; 3047 } 3048 map* fname=getMapFromMaps(outputs,outputs->name,"filename"); 3049 if(fname!=NULL) 3050 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 3051 map* rs=getMapFromMaps(outputs,outputs->name,"size"); 3052 if(rs!=NULL) 3053 printf("Content-Length: %s\r\n",rs->value); 3054 char mime[1024]; 3055 map* mi=getMap(outputs->content,"mimeType"); 3056 map* en=getMap(outputs->content,"encoding"); 3057 if(mi!=NULL && en!=NULL) 3058 sprintf(mime, 3059 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 3060 mi->value,en->value); 3061 else 3062 if(mi!=NULL) 3063 sprintf(mime, 3064 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 3065 mi->value); 3066 else 3067 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 3068 printf("%s",mime); 3069 if(rs!=NULL) 3070 fwrite(toto->value,1,atoi(rs->value),stdout); 3071 else 3072 fwrite(toto->value,1,strlen(toto->value),stdout); 3000 3073 } 3001 3074
Note: See TracChangeset
for help on using the changeset viewer.