Changeset 741 for branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c
- Timestamp:
- Oct 7, 2015, 8:41:43 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c
r677 r741 93 93 * @param m the map containing the headers informations 94 94 */ 95 void printHeaders(maps* m ){95 void printHeaders(maps* m,FCGX_Stream *out){ 96 96 maps *_tmp=getMaps(m,"headers"); 97 97 if(_tmp!=NULL){ 98 98 map* _tmp1=_tmp->content; 99 99 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); 101 101 _tmp1=_tmp1->next; 102 102 } … … 1445 1445 * @param outputs the outputs generated by the service 1446 1446 */ 1447 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs ){1447 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs,FCGX_Stream * out){ 1448 1448 xmlNsPtr ns,ns_ows,ns_xlink; 1449 1449 xmlNodePtr nr,n,nc,nc1=NULL,nc3; … … 1540 1540 hasStoredExecuteResponse=true; 1541 1541 } 1542 1543 1542 nc = xmlNewNode(ns, BAD_CAST "Process"); 1544 1543 map* tmp2=getMap(serv->content,"processVersion"); … … 1548 1547 map* tmpI=getMapFromMaps(m,"lenv","oIdentifier"); 1549 1548 printDescription(nc,ns_ows,tmpI->value,serv->content,0); 1550 1551 1549 xmlAddChild(n,nc); 1552 1550 … … 1695 1693 if(lid<0){ 1696 1694 /* If the lock failed */ 1697 errorException(m,_("Lock failed."),"InternalError",NULL );1695 errorException(m,_("Lock failed."),"InternalError",NULL,out); 1698 1696 xmlFreeDoc(doc); 1699 1697 xmlCleanupParser(); … … 1710 1708 sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path); 1711 1709 1712 errorException(m,tmpMsg,"InternalError",NULL );1710 errorException(m,tmpMsg,"InternalError",NULL,out); 1713 1711 xmlFreeDoc(doc); 1714 1712 xmlCleanupParser(); … … 1738 1736 #endif 1739 1737 } 1740 printDocument(m,doc,pid );1738 printDocument(m,doc,pid,out); 1741 1739 1742 1740 xmlCleanupParser(); … … 1751 1749 * @param pid the process identifier linked to a service 1752 1750 */ 1753 void printDocument(maps* m, xmlDocPtr doc,int pid ){1751 void printDocument(maps* m, xmlDocPtr doc,int pid,FCGX_Stream * out){ 1754 1752 char *encoding=getEncoding(m); 1755 1753 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 } 1760 1757 xmlChar *xmlbuff; 1761 1758 int buffersize; … … 1765 1762 */ 1766 1763 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 } 1769 1768 /* 1770 1769 * Free associated memory. … … 2099 2098 * @param s the map containing the text,code,locator keys 2100 2099 */ 2101 void printExceptionReportResponse(maps* m,map* s ){2100 void printExceptionReportResponse(maps* m,map* s,FCGX_Stream * out){ 2102 2101 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) 2103 2102 return; … … 2135 2134 if(tmpSid!=NULL){ 2136 2135 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 } 2140 2139 } 2141 2140 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); 2144 2143 } 2145 2144 }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 } 2148 2147 n=createExceptionReportNode(m,s,1); 2149 2148 xmlDocSetRootElement(doc, n); 2150 2149 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 2151 printf("%s",xmlbuff); 2152 fflush(stdout); 2150 FCGX_FPrintF(out,"%s",xmlbuff); 2151 FCGX_FFlush(out); 2152 2153 2153 xmlFreeDoc(doc); 2154 2154 xmlFree(xmlbuff); … … 2161 2161 /** 2162 2162 * 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); 2164 2164 * @param m the conf maps 2165 2165 * @param s the map containing the text,code,locator keys … … 2241 2241 * @param locator the potential locator 2242 2242 */ 2243 int errorException(maps *m, const char *message, const char *errorcode, const char *locator )2243 int errorException(maps *m, const char *message, const char *errorcode, const char *locator,FCGX_Stream * out) 2244 2244 { 2245 2245 map* errormap = createMap("text", message); … … 2249 2249 else 2250 2250 addToMap(errormap,"locator", "NULL"); 2251 printExceptionReportResponse(m,errormap );2251 printExceptionReportResponse(m,errormap,out); 2252 2252 freeMap(&errormap); 2253 2253 free(errormap); … … 2267 2267 */ 2268 2268 void 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){ 2270 2270 #ifdef DEBUG 2271 2271 dumpMaps(request_inputs); … … 2278 2278 asRaw=1; 2279 2279 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"); 2283 2282 if(tmpSess!=NULL){ 2284 2283 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 2285 2284 char* sessId=NULL; 2286 2285 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"); 2289 2288 char session_file_path[100]; 2290 2289 char *tmp1=strtok(_tmp->value,";"); … … 2314 2313 char tmpMsg[1024]; 2315 2314 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); 2317 2316 2318 2317 return; … … 2323 2322 } 2324 2323 } 2325 2326 2324 if(res==SERVICE_FAILED){ 2327 2325 map *lenv; … … 2336 2334 sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service.")); 2337 2335 } 2338 errorException(m,tmp0,"InternalError",NULL );2336 errorException(m,tmp0,"InternalError",NULL,out); 2339 2337 free(tmp0); 2340 2338 return; 2341 2339 } 2342 2343 2340 if(res==SERVICE_ACCEPTED && vid==1){ 2344 2341 map* statusInfo=createMap("Status","Accepted"); 2345 2342 map *usid=getMapFromMaps(m,"lenv","usid"); 2346 2343 addToMap(statusInfo,"JobID",usid->value); 2347 printStatusInfo(m,statusInfo,"Execute" );2344 printStatusInfo(m,statusInfo,"Execute",out); 2348 2345 freeMap(&statusInfo); 2349 2346 free(statusInfo); 2350 2347 return; 2351 2348 } 2352 2353 2349 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2354 2350 if(asRaw==0){ … … 2411 2407 getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32); 2412 2408 } 2413 2414 2409 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2415 2410 sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); … … 2422 2417 char tmpMsg[1024]; 2423 2418 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); 2425 2420 free(file_name); 2426 2421 free(file_path); … … 2428 2423 } 2429 2424 free(file_path); 2430 2431 2425 toto=getMap(tmpI->content,"value"); 2432 2426 if(strcasecmp(format,"BoundingBoxData")!=0){ … … 2438 2432 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2439 2433 }else{ 2440 printBoundingBoxDocument(m,tmpI,ofile );2434 printBoundingBoxDocument(m,tmpI,ofile,out); 2441 2435 } 2442 2436 fclose(ofile); 2443 2437 2444 2438 } 2445 2439 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2446 2440 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2447 2441 char *file_url; … … 2473 2467 dumpMaps(m); 2474 2468 #endif 2469 2475 2470 printProcessResponse(m,request_inputs1,cpid, 2476 2471 s, s->name,res, // replace serviceProvider with serviceName in stored response file name 2477 2472 request_inputs, 2478 request_outputs); 2473 request_outputs,out); 2474 2479 2475 } 2480 2476 else{ … … 2492 2488 elements* e=getElements(s->outputs,tmpI->name); 2493 2489 if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ 2494 printBoundingBoxDocument(m,tmpI,NULL );2490 printBoundingBoxDocument(m,tmpI,NULL,out); 2495 2491 }else{ 2496 2492 map *gfile=getMap(tmpI->content,"generated_file"); … … 2506 2502 char tmpMsg[1024]; 2507 2503 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); 2509 2505 return; 2510 2506 } 2511 2507 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2512 2508 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); 2514 2510 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2515 2511 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); 2518 2514 char mime[1024]; 2519 2515 map* mi=getMap(tmpI->content,"mimeType"); … … 2524 2520 #endif 2525 2521 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); 2542 2539 #ifdef DEBUG 2543 2540 dumpMap(toto); … … 2659 2656 * @see parseBoundingBox, printBoundingBox 2660 2657 */ 2661 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){ 2662 if(file==NULL) 2663 rewind(stdout); 2658 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file,FCGX_Stream * out){ 2664 2659 xmlNodePtr n; 2665 2660 xmlDocPtr doc; … … 2675 2670 pid=atoi(tmp->value); 2676 2671 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); 2680 2676 } 2681 2677 … … 2695 2691 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 2696 2692 if(file==NULL) 2697 printf("%s",xmlbuff);2693 FCGX_FPrintF(out,"%s",xmlbuff); 2698 2694 else{ 2699 2695 fprintf(file,"%s",xmlbuff); … … 2723 2719 * @param req the WPS requests (GetResult, GetStatus or Dismiss) 2724 2720 */ 2725 void printStatusInfo(maps* conf,map* statusInfo,char* req ){2726 rewind(stdout);2721 void printStatusInfo(maps* conf,map* statusInfo,char* req,FCGX_Stream * out){ 2722 //rewind(stdout); 2727 2723 xmlNodePtr n,n1; 2728 2724 xmlDocPtr doc; … … 2733 2729 map *tmp; 2734 2730 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); 2736 2733 2737 2734 map* version=getMapFromMaps(conf,"main","rversion"); 2738 2735 int vid=getVersionId(version->value); 2739 2740 2736 doc = xmlNewDoc(BAD_CAST "1.0"); 2741 2737 n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1); … … 2772 2768 2773 2769 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 2774 printf("%s",xmlbuff); 2775 2770 FCGX_FPrintF(out,"%s",xmlbuff); 2776 2771 xmlFree(xmlbuff); 2777 2772 xmlFreeDoc(doc);
Note: See TracChangeset
for help on using the changeset viewer.