Index: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.c	(revision 531)
+++ branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.c	(revision 549)
@@ -58,5 +58,5 @@
 
 void
-printHeaders (maps * m)
+printHeaders (maps * m,FCGX_Stream *out)
 {
   maps *_tmp = getMaps (m, "headers");
@@ -66,5 +66,6 @@
       while (_tmp1 != NULL)
         {
-          printf ("%s: %s\r\n", _tmp1->name, _tmp1->value);
+          FCGX_FPrintF(out,"%s: %s\r\n", _tmp1->name, _tmp1->value);
+          //printf ("%s: %s\r\n", _tmp1->name, _tmp1->value);
           _tmp1 = _tmp1->next;
         }
@@ -100,5 +101,5 @@
 
 #include <windows.h>
-#include <fcgi_stdio.h>
+//#include <fcgi_stdio.h>
 #include <stdio.h>
 #include <conio.h>
@@ -1689,5 +1690,5 @@
 printProcessResponse (maps * m, map * request, int pid, service * serv,
                       const char *service, int status, maps * inputs,
-                      maps * outputs)
+                      maps * outputs, FCGX_Stream* out)
 {
   xmlNsPtr ns, ns_ows, ns_xlink, ns_xsi;
@@ -1990,5 +1991,5 @@
           map *errormap = createMap ("text", tmpMsg);
           addToMap (errormap, "code", "InternalError");
-          printExceptionReportResponse (m, errormap);
+          printExceptionReportResponse (m, errormap,out);
           freeMap (&errormap);
           free (errormap);
@@ -2005,5 +2006,5 @@
       fclose (output);
     }
-  printDocument (m, doc, pid);
+  printDocument (m, doc, pid,out);
 
   xmlCleanupParser ();
@@ -2013,14 +2014,14 @@
 
 void
-printDocument (maps * m, xmlDocPtr doc, int pid)
+printDocument (maps * m, xmlDocPtr doc, int pid,FCGX_Stream * out)
 {
   char *encoding = getEncoding (m);
   if (pid == getpid ())
     {
-      printHeaders (m);
-      printf ("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",
-              encoding);
-    }
-  fflush (stdout);
+      printHeaders (m,out);
+      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+      //printf ("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+    }
+  //fflush (stdout);
   xmlChar *xmlbuff;
   int buffersize;
@@ -2030,6 +2031,8 @@
    */
   xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1);
-  printf ("%s", xmlbuff);
-  fflush (stdout);
+  FCGX_FPrintF(out,(char *)xmlbuff);
+  FCGX_FFlush(out);
+  //printf ("%s", xmlbuff);
+  //fflush (stdout);
   /*
    * Free associated memory.
@@ -2462,5 +2465,5 @@
 
 void
-printExceptionReportResponse (maps * m, map * s)
+printExceptionReportResponse (maps * m, map * s,FCGX_Stream * out)
 {
   if (getMapFromMaps (m, "lenv", "hasPrinted") != NULL)
@@ -2504,27 +2507,29 @@
           if (getpid () == atoi (tmpSid->value))
             {
-              printHeaders (m);
-              printf
-                ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",
-                 encoding, exceptionCode);
+              printHeaders (m,out);
+              FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
+              //printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
             }
         }
       else
         {
-          printHeaders (m);
-          printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",
-                  encoding, exceptionCode);
+          printHeaders (m,out);
+          FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",
+                            encoding, exceptionCode);
+          //printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
         }
     }
   else
-    {
-      printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",
-              encoding, exceptionCode);
+    { 
+      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
+      //printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
     }
   n = createExceptionReportNode (m, s, 1);
   xmlDocSetRootElement (doc, n);
   xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1);
-  printf ("%s", xmlbuff);
-  fflush (stdout);
+  //printf ("%s", xmlbuff);
+  FCGX_FPrintF(out,"%s",xmlbuff);
+FCGX_FFlush(out);
+  //fflush (stdout);
   xmlFreeDoc (doc);
   xmlFree (xmlbuff);
@@ -2595,6 +2600,8 @@
 void
 outputResponse (service * s, maps * request_inputs, maps * request_outputs,
-                map * request_inputs1, int cpid, maps * m, int res)
-{
+                map * request_inputs1, int cpid, maps * m, int res,FCGX_Stream *out,FCGX_Stream *err)
+{
+
+
 #ifdef DEBUG
   dumpMaps (request_inputs);
@@ -2655,5 +2662,5 @@
           addToMap (errormap, "code", "InternalError");
 
-          printExceptionReportResponse (m, errormap);
+          printExceptionReportResponse (m, errormap,out);
           freeMap (&errormap);
           free (errormap);
@@ -2670,4 +2677,6 @@
   if (asRaw == 0)
     {
+
+
 #ifdef DEBUG
       fprintf (stderr, "REQUEST_OUTPUTS FINAL\n");
@@ -2760,5 +2769,6 @@
                   map *errormap = createMap ("text", tmpMsg);
                   addToMap (errormap, "code", "InternalError");
-                  printExceptionReportResponse (m, errormap);
+
+                  printExceptionReportResponse (m, errormap,out);
                   freeMap (&errormap);
                   free (errormap);
@@ -2833,10 +2843,12 @@
       printProcessResponse (m, request_inputs1, cpid,
                             s, r_inputs->value, res,
-                            request_inputs, request_outputs);
+                            request_inputs, request_outputs,out);
     }
   else
     {
+
       if (res == SERVICE_FAILED)
         {
+
           map *errormap;
           map *lenv;
@@ -2871,5 +2883,5 @@
           free (tmp0);
           addToMap (errormap, "code", "InternalError");
-          printExceptionReportResponse (m, errormap);
+          printExceptionReportResponse (m, errormap,out);
           freeMap (&errormap);
           free (errormap);
@@ -2880,4 +2892,6 @@
        * requested one is not present in the resulting outputs maps.
        */
+
+
       maps *tmpI = NULL;
       map *tmpIV = getMap (request_inputs1, "RawDataOutput");
@@ -2905,5 +2919,5 @@
               map *errormap = createMap ("text", tmpMsg);
               addToMap (errormap, "code", "InvalidParameterValue");
-              printExceptionReportResponse (m, errormap);
+              printExceptionReportResponse (m, errormap,out);
               freeMap (&errormap);
               free (errormap);
@@ -2912,10 +2926,11 @@
           map *fname = getMapFromMaps (tmpI, tmpI->name, "filename");
           if (fname != NULL)
-            printf ("Content-Disposition: attachment; filename=\"%s\"\r\n",
-                    fname->value);
+            FCGX_FPrintF(out,"Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
+            //printf ("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
           map *rs = getMapFromMaps (tmpI, tmpI->name, "size");
           if (rs != NULL)
-            printf ("Content-Length: %s\r\n", rs->value);
-          printHeaders (m);
+            FCGX_FPrintF(out,"Content-Length: %s\r\n", rs->value);
+            //printf ("Content-Length: %s\r\n", rs->value);
+          printHeaders (m,out);
           char mime[1024];
           map *mi = getMap (tmpI->content, "mimeType");
@@ -2937,9 +2952,15 @@
             sprintf (mime,
                      "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-          printf ("%s", mime);
+          FCGX_FPrintF(out,"%s", mime);
+
+          //printf ("%s", mime);
           if (rs != NULL)
-            fwrite (toto->value, 1, atoi (rs->value), stdout);
+            FCGX_PutStr(toto->value,atoi(rs->value),out);
+            //fwrite (toto->value, 1, atoi (rs->value), stdout);
           else
-            fwrite (toto->value, 1, strlen (toto->value), stdout);
+             FCGX_PutStr(toto->value,strlen (toto->value),out);
+            //fwrite (toto->value, 1, strlen (toto->value), stdout);
+
+          FCGX_FFlush(out);
 #ifdef DEBUG
           dumpMap (toto);
@@ -3400,6 +3421,6 @@
 printBoundingBoxDocument (maps * m, maps * boundingbox, FILE * file)
 {
-  if (file == NULL)
-    rewind (stdout);
+  //if (file == NULL)
+   // rewind (stdout);
   xmlNodePtr n;
   xmlDocPtr doc;
@@ -3421,5 +3442,5 @@
              encoding);
         }
-      fflush (stdout);
+      //fflush (stdout);
     }
 
@@ -3583,5 +3604,5 @@
                       return errorException (*m,
                                              _("Unable to allocate memory."),
-                                             "InternalError", NULL);
+                                             "InternalError", NULL,NULL);
                     }
                   size_t dwRead;
@@ -3603,5 +3624,5 @@
                       return errorException (*m,
                                              _("Unable to allocate memory."),
-                                             "InternalError", NULL);
+                                             "InternalError", NULL,NULL);
                     }
                   memcpy (tmpMap->value, fcontent,
@@ -3667,5 +3688,5 @@
     {
       return errorException (*m, _("Unable to download the file."),
-                             "InternalError", NULL);
+                             "InternalError", NULL,NULL);
     }
   if (mimeType != NULL)
@@ -3680,5 +3701,5 @@
   if (tmpMap->value == NULL)
     return errorException (*m, _("Unable to allocate memory."),
-                           "InternalError", NULL);
+                           "InternalError", NULL,NULL);
   memcpy (tmpMap->value, fcontent, (fsize + 1) * sizeof (char));
 
@@ -3698,5 +3719,5 @@
 int
 errorException (maps * m, const char *message, const char *errorcode,
-                const char *locator)
+                const char *locator,FCGX_Stream * out)
 {
   map *errormap = createMap ("text", message);
@@ -3706,5 +3727,5 @@
   else
     addToMap (errormap, "locator", "NULL");
-  printExceptionReportResponse (m, errormap);
+  printExceptionReportResponse (m, errormap,out);
   freeMap (&errormap);
   free (errormap);
