Index: /trunk/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- /trunk/zoo-project/zoo-kernel/Makefile.in	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/Makefile.in	(revision 446)
@@ -14,5 +14,5 @@
 MS_FILE=@MS_FILE@
 
-CFLAGS=${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+CFLAGS=-fpic ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
 LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS}
 
Index: /trunk/zoo-project/zoo-kernel/main_conf_read.y
===================================================================
--- /trunk/zoo-project/zoo-kernel/main_conf_read.y	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/main_conf_read.y	(revision 446)
@@ -6,9 +6,5 @@
 //======================================================
 
-#include <string>
-#include <stdio.h>
-#include <ctype.h>
 #include <service.h>
-#include <vector>
 
 static int defaultsc=0;
Index: /trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.h	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/service.h	(revision 446)
@@ -268,5 +268,4 @@
       map* icurs=curs->content;
       if(type==0){
-	map* tmp=getMap(curs->content,"value");
 	char *temp=strdup(dataInputsKVP);
 	if(getMap(m->content,"xlink:href")!=NULL)
@@ -276,5 +275,4 @@
 	free(temp);
       }
-      int j=0;
       while(icurs!=NULL){
 	if(strcasecmp(icurs->name,"value")!=0 &&
@@ -686,5 +684,4 @@
     }
 
-    map* tmpValI=getMap(tmp->content,"value");
     char *tmpV[8]={
       "size",
@@ -701,5 +698,5 @@
     int i=0;
     map* tmpSizeI=getMap(tmp->content,tmpV[i]);
-    for(0;i<8;i++){
+    for(i=0;i<8;i++){
       map* tmpVI=getMap(tmp->content,tmpV[i]);
       if(tmpVI!=NULL){
Index: /trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 446)
@@ -2516,5 +2516,5 @@
  * Cache a file for a given request
  */
-void addToCache(maps* conf,char* request,char* content,int length){
+void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){
   map* tmp=getMapFromMaps(conf,"main","cacheDir");
   if(tmp!=NULL){
@@ -2529,4 +2529,13 @@
     fwrite(content,sizeof(char),length,fo);
     fclose(fo);
+
+    sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
+    fo=fopen(fname,"w+");
+#ifdef DEBUG
+    fprintf(stderr,"MIMETYPE: %s\n",mimeType);
+#endif
+    fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
+    fclose(fo);
+
     free(md5str);
     free(fname);
@@ -2563,4 +2572,5 @@
   char* fcontent;
   char* cached=isInCache(m,url);
+  char *mimeType=NULL;
   int fsize;
   int hasF=-1;
@@ -2574,4 +2584,14 @@
       fsize=f_status.st_size;
       fcontent[fsize]=0;
+      fclose(f);
+    }
+    cached[strlen(cached)-1]='m';
+    s=stat(cached, &f_status);
+    if(s==0){
+      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(cached,"rb");
+      int len=fread(mimeType,f_status.st_size,1,f);
+      mimeType[f_status.st_size]=0;
+      fclose(f);
     }
   }else{
@@ -2585,7 +2605,12 @@
     fcontent[res.nDataLen]=0;
     fsize=res.nDataLen;
+    mimeType=res.mimeType;
   }
   if(fsize==0){
     return errorException(m, _("Unable to download the file."), "InternalError");
+  }
+
+  if(mimeType!=NULL){
+    addToMap(content,"fmimeType",mimeType);
   }
 
@@ -2603,6 +2628,8 @@
   addToMap(content,"size",ltmp1);
   if(cached==NULL)
-    addToCache(m,url,fcontent,fsize);
+    addToCache(m,url,fcontent,mimeType,fsize);
   else{
+    free(fcontent);
+    free(mimeType);
     free(cached);
   }
Index: /trunk/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 446)
@@ -131,5 +131,5 @@
   int checkForSoapEnvelope(xmlDocPtr);
 
-  void addToCache(maps*,char*,char*,int);
+  void addToCache(maps*,char*,char*,char*,int);
   char* isInCache(maps*,char*);
   int loadRemoteFile(maps*,map*,HINTERNET,char*);
Index: /trunk/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/ulinet.c	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/ulinet.c	(revision 446)
@@ -39,9 +39,9 @@
   psInternet=(HINTERNET *)data;
   if(psInternet->pabyData){
-    psInternet->pabyData=(char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1);
+    psInternet->pabyData=(unsigned char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1);
     psInternet->nDataAlloc+=psInternet->nDataLen+realsize+1;
   }
   else{
-    psInternet->pabyData=(char*)malloc(psInternet->nDataLen+realsize+1);
+    psInternet->pabyData=(unsigned char*)malloc(psInternet->nDataLen+realsize+1);
     psInternet->nDataAlloc=realsize+1;
   }
@@ -106,7 +106,7 @@
   CFArrayRef		proxies;
   
-  CFStringRef key_enabled;
-  CFStringRef key_host;
-  CFStringRef key_port;
+  CFStringRef key_enabled = NULL;
+  CFStringRef key_host = NULL;
+  CFStringRef key_port = NULL;
   
   bool proxy_enabled;
@@ -120,5 +120,5 @@
   proxyDict = SCDynamicStoreCopyProxies(NULL);
 
-  if(proto=="http"){
+  if(strncmp(proto,"http",4)==0){
       key_enabled=kSCPropNetProxiesHTTPEnable;
       key_host=kSCPropNetProxiesHTTPProxy;
@@ -126,5 +126,5 @@
   }
   else
-    if(proto=="https"){
+    if(strncmp(proto,"https",5)==0){
       key_enabled=kSCPropNetProxiesHTTPSEnable;
       key_host=kSCPropNetProxiesHTTPSProxy;
@@ -168,4 +168,5 @@
   ret.hasCacheFile=0;
   ret.nDataAlloc = 0;
+  ret.mimeType = NULL;
 
   ret.handle=curl_easy_init();
@@ -191,15 +192,4 @@
 
   return ret;
-}
-
-static size_t 
-CurlWriteCB(void *buffer, size_t size, size_t nmemb, void *reqInfo){
-  HINTERNET *psInternet = (HINTERNET *) reqInfo;
-
-  memcpy( psInternet->pabyData + psInternet->nDataLen, buffer,  nmemb * size );
-  psInternet->nDataLen += nmemb * size;
-  psInternet->pabyData[psInternet->nDataLen] = 0;
-
-  return nmemb *size;
 }
 
@@ -208,7 +198,9 @@
     fclose(handle.file);
     unlink(handle.filename);
+    handle.mimeType = NULL;
   }
   else{
     handle.pabyData = NULL;
+    handle.mimeType = NULL;
     handle.nDataAlloc = handle.nDataLen = 0;
   }
@@ -271,5 +263,8 @@
   curl_easy_setopt(hInternet.handle,CURLOPT_URL,lpszUrl);
   curl_easy_perform(hInternet.handle);
-
+  curl_easy_getinfo(hInternet.handle,CURLINFO_CONTENT_TYPE,&hInternet.mimeType);
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"DEBUG MIMETYPE: %s\n",hInternet.mimeType);
+#endif
   return hInternet;
 };
Index: /trunk/zoo-project/zoo-kernel/ulinet.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/ulinet.h	(revision 445)
+++ /trunk/zoo-project/zoo-kernel/ulinet.h	(revision 446)
@@ -26,4 +26,5 @@
 #define _ULINET_H
 
+#include "fcgi_stdio.h"
 #include <stdlib.h>
 #include <fcntl.h>
@@ -72,4 +73,5 @@
   int nDataAlloc;
   unsigned char *pabyData;
+  unsigned char *mimeType;
 } HINTERNET;
 
