Changeset 446 for trunk


Ignore:
Timestamp:
Oct 30, 2013, 1:24:11 PM (11 years ago)
Author:
djay
Message:

Detect mimetype of downloaded content.

Location:
trunk/zoo-project/zoo-kernel
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/Makefile.in

    r408 r446  
    1414MS_FILE=@MS_FILE@
    1515
    16 CFLAGS=${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
     16CFLAGS=-fpic ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
    1717LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS}
    1818
  • trunk/zoo-project/zoo-kernel/main_conf_read.y

    r385 r446  
    66//======================================================
    77
    8 #include <string>
    9 #include <stdio.h>
    10 #include <ctype.h>
    118#include <service.h>
    12 #include <vector>
    139
    1410static int defaultsc=0;
  • trunk/zoo-project/zoo-kernel/service.h

    r444 r446  
    268268      map* icurs=curs->content;
    269269      if(type==0){
    270         map* tmp=getMap(curs->content,"value");
    271270        char *temp=strdup(dataInputsKVP);
    272271        if(getMap(m->content,"xlink:href")!=NULL)
     
    276275        free(temp);
    277276      }
    278       int j=0;
    279277      while(icurs!=NULL){
    280278        if(strcasecmp(icurs->name,"value")!=0 &&
     
    686684    }
    687685
    688     map* tmpValI=getMap(tmp->content,"value");
    689686    char *tmpV[8]={
    690687      "size",
     
    701698    int i=0;
    702699    map* tmpSizeI=getMap(tmp->content,tmpV[i]);
    703     for(0;i<8;i++){
     700    for(i=0;i<8;i++){
    704701      map* tmpVI=getMap(tmp->content,tmpV[i]);
    705702      if(tmpVI!=NULL){
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r442 r446  
    25162516 * Cache a file for a given request
    25172517 */
    2518 void addToCache(maps* conf,char* request,char* content,int length){
     2518void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){
    25192519  map* tmp=getMapFromMaps(conf,"main","cacheDir");
    25202520  if(tmp!=NULL){
     
    25292529    fwrite(content,sizeof(char),length,fo);
    25302530    fclose(fo);
     2531
     2532    sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
     2533    fo=fopen(fname,"w+");
     2534#ifdef DEBUG
     2535    fprintf(stderr,"MIMETYPE: %s\n",mimeType);
     2536#endif
     2537    fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
     2538    fclose(fo);
     2539
    25312540    free(md5str);
    25322541    free(fname);
     
    25632572  char* fcontent;
    25642573  char* cached=isInCache(m,url);
     2574  char *mimeType=NULL;
    25652575  int fsize;
    25662576  int hasF=-1;
     
    25742584      fsize=f_status.st_size;
    25752585      fcontent[fsize]=0;
     2586      fclose(f);
     2587    }
     2588    cached[strlen(cached)-1]='m';
     2589    s=stat(cached, &f_status);
     2590    if(s==0){
     2591      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     2592      FILE* f=fopen(cached,"rb");
     2593      int len=fread(mimeType,f_status.st_size,1,f);
     2594      mimeType[f_status.st_size]=0;
     2595      fclose(f);
    25762596    }
    25772597  }else{
     
    25852605    fcontent[res.nDataLen]=0;
    25862606    fsize=res.nDataLen;
     2607    mimeType=res.mimeType;
    25872608  }
    25882609  if(fsize==0){
    25892610    return errorException(m, _("Unable to download the file."), "InternalError");
     2611  }
     2612
     2613  if(mimeType!=NULL){
     2614    addToMap(content,"fmimeType",mimeType);
    25902615  }
    25912616
     
    26032628  addToMap(content,"size",ltmp1);
    26042629  if(cached==NULL)
    2605     addToCache(m,url,fcontent,fsize);
     2630    addToCache(m,url,fcontent,mimeType,fsize);
    26062631  else{
     2632    free(fcontent);
     2633    free(mimeType);
    26072634    free(cached);
    26082635  }
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r392 r446  
    131131  int checkForSoapEnvelope(xmlDocPtr);
    132132
    133   void addToCache(maps*,char*,char*,int);
     133  void addToCache(maps*,char*,char*,char*,int);
    134134  char* isInCache(maps*,char*);
    135135  int loadRemoteFile(maps*,map*,HINTERNET,char*);
  • trunk/zoo-project/zoo-kernel/ulinet.c

    r375 r446  
    3939  psInternet=(HINTERNET *)data;
    4040  if(psInternet->pabyData){
    41     psInternet->pabyData=(char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1);
     41    psInternet->pabyData=(unsigned char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1);
    4242    psInternet->nDataAlloc+=psInternet->nDataLen+realsize+1;
    4343  }
    4444  else{
    45     psInternet->pabyData=(char*)malloc(psInternet->nDataLen+realsize+1);
     45    psInternet->pabyData=(unsigned char*)malloc(psInternet->nDataLen+realsize+1);
    4646    psInternet->nDataAlloc=realsize+1;
    4747  }
     
    106106  CFArrayRef            proxies;
    107107 
    108   CFStringRef key_enabled;
    109   CFStringRef key_host;
    110   CFStringRef key_port;
     108  CFStringRef key_enabled = NULL;
     109  CFStringRef key_host = NULL;
     110  CFStringRef key_port = NULL;
    111111 
    112112  bool proxy_enabled;
     
    120120  proxyDict = SCDynamicStoreCopyProxies(NULL);
    121121
    122   if(proto=="http"){
     122  if(strncmp(proto,"http",4)==0){
    123123      key_enabled=kSCPropNetProxiesHTTPEnable;
    124124      key_host=kSCPropNetProxiesHTTPProxy;
     
    126126  }
    127127  else
    128     if(proto=="https"){
     128    if(strncmp(proto,"https",5)==0){
    129129      key_enabled=kSCPropNetProxiesHTTPSEnable;
    130130      key_host=kSCPropNetProxiesHTTPSProxy;
     
    168168  ret.hasCacheFile=0;
    169169  ret.nDataAlloc = 0;
     170  ret.mimeType = NULL;
    170171
    171172  ret.handle=curl_easy_init();
     
    191192
    192193  return ret;
    193 }
    194 
    195 static size_t
    196 CurlWriteCB(void *buffer, size_t size, size_t nmemb, void *reqInfo){
    197   HINTERNET *psInternet = (HINTERNET *) reqInfo;
    198 
    199   memcpy( psInternet->pabyData + psInternet->nDataLen, buffer,  nmemb * size );
    200   psInternet->nDataLen += nmemb * size;
    201   psInternet->pabyData[psInternet->nDataLen] = 0;
    202 
    203   return nmemb *size;
    204194}
    205195
     
    208198    fclose(handle.file);
    209199    unlink(handle.filename);
     200    handle.mimeType = NULL;
    210201  }
    211202  else{
    212203    handle.pabyData = NULL;
     204    handle.mimeType = NULL;
    213205    handle.nDataAlloc = handle.nDataLen = 0;
    214206  }
     
    271263  curl_easy_setopt(hInternet.handle,CURLOPT_URL,lpszUrl);
    272264  curl_easy_perform(hInternet.handle);
    273 
     265  curl_easy_getinfo(hInternet.handle,CURLINFO_CONTENT_TYPE,&hInternet.mimeType);
     266#ifdef ULINET_DEBUG
     267  fprintf(stderr,"DEBUG MIMETYPE: %s\n",hInternet.mimeType);
     268#endif
    274269  return hInternet;
    275270};
  • trunk/zoo-project/zoo-kernel/ulinet.h

    r368 r446  
    2626#define _ULINET_H
    2727
     28#include "fcgi_stdio.h"
    2829#include <stdlib.h>
    2930#include <fcntl.h>
     
    7273  int nDataAlloc;
    7374  unsigned char *pabyData;
     75  unsigned char *mimeType;
    7476} HINTERNET;
    7577
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