Ignore:
Timestamp:
Oct 7, 2015, 8:41:43 AM (9 years ago)
Author:
david
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c

    r677 r741  
    9393 * @param m the map containing the headers informations
    9494 */
    95 void printHeaders(maps* m){
     95void printHeaders(maps* m,FCGX_Stream *out){
    9696  maps *_tmp=getMaps(m,"headers");
    9797  if(_tmp!=NULL){
    9898    map* _tmp1=_tmp->content;
    9999    while(_tmp1!=NULL){
    100       printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
     100      FCGX_FPrintF(out,"%s: %s\r\n", _tmp1->name, _tmp1->value);
    101101      _tmp1=_tmp1->next;
    102102    }
     
    14451445 * @param outputs the outputs generated by the service
    14461446 */
    1447 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
     1447void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs,FCGX_Stream * out){
    14481448  xmlNsPtr ns,ns_ows,ns_xlink;
    14491449  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
     
    15401540      hasStoredExecuteResponse=true;
    15411541    }
    1542 
    15431542    nc = xmlNewNode(ns, BAD_CAST "Process");
    15441543    map* tmp2=getMap(serv->content,"processVersion");
     
    15481547    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
    15491548    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
    1550 
    15511549    xmlAddChild(n,nc);
    15521550
     
    16951693    if(lid<0){
    16961694      /* If the lock failed */
    1697       errorException(m,_("Lock failed."),"InternalError",NULL);
     1695      errorException(m,_("Lock failed."),"InternalError",NULL,out);
    16981696      xmlFreeDoc(doc);
    16991697      xmlCleanupParser();
     
    17101708        sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
    17111709
    1712         errorException(m,tmpMsg,"InternalError",NULL);
     1710        errorException(m,tmpMsg,"InternalError",NULL,out);
    17131711        xmlFreeDoc(doc);
    17141712        xmlCleanupParser();
     
    17381736#endif
    17391737  }
    1740   printDocument(m,doc,pid);
     1738  printDocument(m,doc,pid,out);
    17411739
    17421740  xmlCleanupParser();
     
    17511749 * @param pid the process identifier linked to a service
    17521750 */
    1753 void printDocument(maps* m, xmlDocPtr doc,int pid){
     1751void printDocument(maps* m, xmlDocPtr doc,int pid,FCGX_Stream * out){
    17541752  char *encoding=getEncoding(m);
    17551753  if(pid==getpid()){
    1756     printHeaders(m);
    1757     printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    1758   }
    1759   fflush(stdout);
     1754    printHeaders(m,out);
     1755    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     1756  }
    17601757  xmlChar *xmlbuff;
    17611758  int buffersize;
     
    17651762   */
    17661763  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    1767   printf("%s",xmlbuff);
    1768   fflush(stdout);
     1764  if (out != NULL){
     1765    FCGX_FPrintF(out,(char *)xmlbuff);
     1766    FCGX_FFlush(out);
     1767  }
    17691768  /*
    17701769   * Free associated memory.
     
    20992098 * @param s the map containing the text,code,locator keys
    21002099 */
    2101 void printExceptionReportResponse(maps* m,map* s){
     2100void printExceptionReportResponse(maps* m,map* s,FCGX_Stream * out){
    21022101  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
    21032102    return;
     
    21352134    if(tmpSid!=NULL){
    21362135      if( getpid()==atoi(tmpSid->value) ){
    2137         printHeaders(m);
    2138         printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
    2139       }
     2136        printHeaders(m,out);
     2137    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
     2138          }
    21402139    }
    21412140    else{
    2142       printHeaders(m);
    2143       printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
     2141      printHeaders(m,out);
     2142      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
    21442143    }
    21452144  }else{
    2146     printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
    2147   }
     2145    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
     2146    }
    21482147  n=createExceptionReportNode(m,s,1);
    21492148  xmlDocSetRootElement(doc, n);
    21502149  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    2151   printf("%s",xmlbuff);
    2152   fflush(stdout);
     2150  FCGX_FPrintF(out,"%s",xmlbuff);
     2151  FCGX_FFlush(out);
     2152
    21532153  xmlFreeDoc(doc);
    21542154  xmlFree(xmlbuff);
     
    21612161/**
    21622162 * Create an OWS ExceptionReport Node.
    2163  *
     2163 * FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
    21642164 * @param m the conf maps
    21652165 * @param s the map containing the text,code,locator keys
     
    22412241 * @param locator the potential locator
    22422242 */
    2243 int errorException(maps *m, const char *message, const char *errorcode, const char *locator)
     2243int errorException(maps *m, const char *message, const char *errorcode, const char *locator,FCGX_Stream * out)
    22442244{
    22452245  map* errormap = createMap("text", message);
     
    22492249  else
    22502250    addToMap(errormap,"locator", "NULL");
    2251   printExceptionReportResponse(m,errormap);
     2251  printExceptionReportResponse(m,errormap,out);
    22522252  freeMap(&errormap);
    22532253  free(errormap);
     
    22672267 */
    22682268void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
    2269                     map* request_inputs1,int cpid,maps* m,int res){
     2269                    map* request_inputs1,int cpid,maps* m,int res,FCGX_Stream * out){
    22702270#ifdef DEBUG
    22712271  dumpMaps(request_inputs);
     
    22782278    asRaw=1;
    22792279  map* version=getMapFromMaps(m,"main","rversion");
    2280   int vid=getVersionId(version->value);
    2281  
    2282   maps* tmpSess=getMaps(m,"senv");
     2280   int vid=getVersionId(version->value);
     2281   maps* tmpSess=getMaps(m,"senv");
    22832282  if(tmpSess!=NULL){
    22842283    map *_tmp=getMapFromMaps(m,"lenv","cookie");
    22852284    char* sessId=NULL;
    22862285    if(_tmp!=NULL){
    2287       printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
    2288       printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
     2286      FCGX_FPrintF(out,"Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
     2287      FCGX_FPrintF(out,"P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
    22892288      char session_file_path[100];
    22902289      char *tmp1=strtok(_tmp->value,";");
     
    23142313      char tmpMsg[1024];
    23152314      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
    2316       errorException(m,tmpMsg,"InternalError",NULL);
     2315      errorException(m,tmpMsg,"InternalError",NULL,out);
    23172316
    23182317      return;
     
    23232322    }
    23242323  }
    2325  
    23262324  if(res==SERVICE_FAILED){
    23272325    map *lenv;
     
    23362334      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
    23372335    }
    2338     errorException(m,tmp0,"InternalError",NULL);
     2336    errorException(m,tmp0,"InternalError",NULL,out);
    23392337    free(tmp0);
    23402338    return;
    23412339  }
    2342 
    23432340  if(res==SERVICE_ACCEPTED && vid==1){
    23442341    map* statusInfo=createMap("Status","Accepted");
    23452342    map *usid=getMapFromMaps(m,"lenv","usid");
    23462343    addToMap(statusInfo,"JobID",usid->value);
    2347     printStatusInfo(m,statusInfo,"Execute");
     2344    printStatusInfo(m,statusInfo,"Execute",out);
    23482345    freeMap(&statusInfo);
    23492346    free(statusInfo);
    23502347    return;
    23512348  }
    2352 
    23532349  map *tmp1=getMapFromMaps(m,"main","tmpPath");
    23542350  if(asRaw==0){
     
    24112407              getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
    24122408            }
    2413                
    24142409            file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
    24152410            sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
     
    24222417              char tmpMsg[1024];
    24232418              sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
    2424               errorException(m,tmpMsg,"InternalError",NULL);
     2419              errorException(m,tmpMsg,"InternalError",NULL,out);
    24252420              free(file_name);
    24262421              free(file_path);
     
    24282423            }
    24292424            free(file_path);
    2430 
    24312425            toto=getMap(tmpI->content,"value");
    24322426            if(strcasecmp(format,"BoundingBoxData")!=0){
     
    24382432                  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
    24392433            }else{
    2440               printBoundingBoxDocument(m,tmpI,ofile);
     2434              printBoundingBoxDocument(m,tmpI,ofile,out);
    24412435            }
    24422436            fclose(ofile);
    24432437
    24442438          }
    2445           map *tmp2=getMapFromMaps(m,"main","tmpUrl");
     2439      map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    24462440          map *tmp3=getMapFromMaps(m,"main","serverAddress");
    24472441          char *file_url;
     
    24732467    dumpMaps(m);
    24742468#endif
     2469
    24752470    printProcessResponse(m,request_inputs1,cpid,
    24762471                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
    24772472                         request_inputs,
    2478                          request_outputs);
     2473                         request_outputs,out);
     2474
    24792475  }
    24802476  else{
     
    24922488    elements* e=getElements(s->outputs,tmpI->name);
    24932489    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
    2494       printBoundingBoxDocument(m,tmpI,NULL);
     2490      printBoundingBoxDocument(m,tmpI,NULL,out);
    24952491    }else{
    24962492      map *gfile=getMap(tmpI->content,"generated_file");
     
    25062502        char tmpMsg[1024];
    25072503        sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
    2508         errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
     2504        errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput",out);
    25092505        return;
    25102506      }
    25112507      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
    25122508      if(fname!=NULL)
    2513         printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
     2509      FCGX_FPrintF(out,"Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
    25142510      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
    25152511      if(rs!=NULL)
    2516         printf("Content-Length: %s\r\n",rs->value);
    2517       printHeaders(m);
     2512      FCGX_FPrintF(out,"Content-Length: %s\r\n",rs->value);
     2513      printHeaders(m,out);
    25182514      char mime[1024];
    25192515      map* mi=getMap(tmpI->content,"mimeType");
     
    25242520#endif
    25252521      map* en=getMap(tmpI->content,"encoding");
    2526       if(mi!=NULL && en!=NULL)
    2527         sprintf(mime,
    2528                 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
    2529                 mi->value,en->value);
    2530       else
    2531         if(mi!=NULL)
    2532           sprintf(mime,
    2533                   "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
    2534                   mi->value);
    2535         else
    2536           sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    2537       printf("%s",mime);
    2538       if(rs!=NULL)
    2539         fwrite(toto->value,1,atoi(rs->value),stdout);
    2540       else
    2541         fwrite(toto->value,1,strlen(toto->value),stdout);
     2522      if(mi!=NULL && en!=NULL){
     2523        sprintf(mime,"Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",mi->value,en->value);
     2524      }
     2525      else {
     2526        if(mi!=NULL)
     2527            sprintf(mime,"Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",mi->value);
     2528        else
     2529            sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     2530      }
     2531      FCGX_FPrintF(out,"%s",mime);
     2532      if(rs!=NULL){
     2533        FCGX_PutStr(toto->value,atoi(rs->value),out);
     2534      }
     2535      else {
     2536        FCGX_PutStr(toto->value,strlen (toto->value),out);
     2537      }
     2538    FCGX_FFlush(out);
    25422539#ifdef DEBUG
    25432540      dumpMap(toto);
     
    26592656 * @see parseBoundingBox, printBoundingBox
    26602657 */
    2661 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
    2662   if(file==NULL)
    2663     rewind(stdout);
     2658void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file,FCGX_Stream * out){
    26642659  xmlNodePtr n;
    26652660  xmlDocPtr doc;
     
    26752670      pid=atoi(tmp->value);
    26762671    if(pid==getpid()){
    2677       printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    2678     }
    2679     fflush(stdout);
     2672     
     2673      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     2674    }
     2675    FCGX_FFlush(out);
    26802676  }
    26812677
     
    26952691  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    26962692  if(file==NULL)
    2697     printf("%s",xmlbuff);
     2693   FCGX_FPrintF(out,"%s",xmlbuff);
    26982694  else{
    26992695    fprintf(file,"%s",xmlbuff);
     
    27232719 * @param req the WPS requests (GetResult, GetStatus or Dismiss)
    27242720 */
    2725 void printStatusInfo(maps* conf,map* statusInfo,char* req){
    2726   rewind(stdout);
     2721void printStatusInfo(maps* conf,map* statusInfo,char* req,FCGX_Stream * out){
     2722  //rewind(stdout);
    27272723  xmlNodePtr n,n1;
    27282724  xmlDocPtr doc;
     
    27332729  map *tmp;
    27342730  int pid=0;
    2735   printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
     2731 
     2732  FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
    27362733
    27372734  map* version=getMapFromMaps(conf,"main","rversion");
    27382735  int vid=getVersionId(version->value);
    2739 
    27402736  doc = xmlNewDoc(BAD_CAST "1.0");
    27412737  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
     
    27722768
    27732769  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
    2774   printf("%s",xmlbuff);
    2775 
     2770  FCGX_FPrintF(out,"%s",xmlbuff);
    27762771  xmlFree(xmlbuff);
    27772772  xmlFreeDoc(doc);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png