Ignore:
Timestamp:
Jul 11, 2014, 10:14:03 PM (10 years ago)
Author:
djay
Message:

Inputs passed by reference downloaded in parallel. Conform behavior for DescribeProcess? when the Identifier was not found.

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

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r490 r492  
    18711871      if(testMap!=NULL){
    18721872        HINTERNET hInternet;
     1873        char* tmpValue;
     1874        size_t dwRead;
    18731875        hInternet=InternetOpen(
    18741876#ifndef WIN32
     
    18791881                               NULL,NULL, 0);
    18801882        testMap=getMap(m->content,"Reference");
    1881         loadRemoteFile(&m,&m->content,hInternet,testMap->value);
    1882         InternetCloseHandle(hInternet);
     1883        loadRemoteFile(&m,&m->content,&hInternet,testMap->value);
     1884        processDownloads(&hInternet);
     1885        tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char));
     1886        InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead);
     1887        InternetCloseHandle(&hInternet);
    18831888      }
    18841889#endif
     
    19631968        else
    19641969#endif
    1965           xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
     1970          if(strcasecmp(tmp->name,"datatype")==0)
     1971            xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
     1972          else
     1973            xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
    19661974      }
    19671975      tmp=tmp->next;
     
    28722880    fprintf(stderr,"MIMETYPE: %s\n",mimeType);
    28732881#endif
    2874     fwrite(mimeType,1,strlen(mimeType),fo);
     2882    fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
    28752883    fclose(fo);
    28762884
     
    29012909}
    29022910
     2911int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){
     2912  if(hInternet->nb>0){
     2913    processDownloads(hInternet);
     2914    maps* content=*inputs;
     2915    map* tmp1;
     2916    int index=0;
     2917    while(content!=NULL){
     2918      if((tmp1=getMap(content->content,"href")) ||
     2919         (tmp1=getMap(content->content,"xlink:href"))){
     2920        if(getMap(content->content,"isCached")==NULL){
     2921          char* fcontent;
     2922          char *mimeType=NULL;
     2923          int fsize=0;
     2924
     2925          fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
     2926          if(fcontent == NULL){
     2927            return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
     2928          }
     2929          size_t dwRead;
     2930          InternetReadFile(hInternet->ihandle[index],
     2931                           (LPVOID)fcontent,
     2932                           hInternet->ihandle[index].nDataLen,
     2933                           &dwRead);
     2934          fcontent[hInternet->ihandle[index].nDataLen]=0;
     2935          fsize=hInternet->ihandle[index].nDataLen;
     2936          mimeType=strdup((char*)hInternet->ihandle[index].mimeType);
     2937         
     2938          map* tmpMap=getMapOrFill(&content->content,"value","");
     2939          free(tmpMap->value);
     2940          tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
     2941          if(tmpMap->value==NULL){
     2942            return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
     2943          }
     2944          memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
     2945         
     2946          char ltmp1[256];
     2947          sprintf(ltmp1,"%d",fsize);
     2948          addToMap(content->content,"size",ltmp1);
     2949          addToCache(*m,tmp1->value,fcontent,mimeType,fsize);
     2950          free(fcontent);
     2951          free(mimeType);
     2952        }
     2953        index++;
     2954      }
     2955      content=content->next;
     2956    }
     2957  }
     2958}
     2959
    29032960/**
    29042961 * loadRemoteFile:
    29052962 * Try to load file from cache or download a remote file if not in cache
    29062963 */
    2907 int loadRemoteFile(maps** m,map** content,HINTERNET hInternet,char *url){
    2908   HINTERNET res;
     2964int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
    29092965  char* fcontent;
    29102966  char* cached=isInCache(*m,url);
     
    29322988    }
    29332989  }else{
    2934     res=InternetOpenUrl(hInternet,url,NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
    2935     fcontent=(char*)malloc((res.nDataLen+1)*sizeof(char));
    2936     if(fcontent == NULL){
    2937       return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
    2938     }
    2939     size_t dwRead;
    2940     InternetReadFile(res, (LPVOID)fcontent, res.nDataLen, &dwRead);
    2941     fcontent[res.nDataLen]=0;
    2942     fsize=res.nDataLen;
    2943     mimeType=(char*)res.mimeType;
     2990    hInternet->waitingRequests[hInternet->nb]=strdup(url);
     2991    InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
     2992    return 0;
    29442993  }
    29452994  if(fsize==0){
    29462995    return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
    29472996  }
    2948 
    29492997  if(mimeType!=NULL){
    29502998    addToMap(*content,"fmimeType",mimeType);
     
    29573005  if(tmpMap->value==NULL)
    29583006    return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
    2959   //snprintf(tmpMap->value,(fsize+1)*sizeof(char),fcontent);
    29603007  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
    29613008 
     
    29653012  if(cached==NULL)
    29663013    addToCache(*m,url,fcontent,mimeType,fsize);
     3014  else
     3015    addToMap(*content,"isCached","true");
    29673016  free(fcontent);
    29683017  free(mimeType);
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r490 r492  
    148148  void addToCache(maps*,char*,char*,char*,int);
    149149  char* isInCache(maps*,char*);
    150   int loadRemoteFile(maps**,map**,HINTERNET,char*);
     150  int runHttpRequests(maps**,maps**,HINTERNET*);
     151  int loadRemoteFile(maps**,map**,HINTERNET*,char*);
    151152
    152153  char *readVSIFile(maps*,const char*);
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r471 r492  
    732732}
    733733
    734 HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){
     734HINTERNET setHeader(HINTERNET* handle,JSContext *cx,JSObject *header){
    735735  jsuint length=0;
    736736  jsint i=0;
     
    747747    fprintf(stderr,"header is an array of %d elements\n",length);
    748748#endif
    749     handle.header=NULL;
     749    handle->ihandle[handle->nb].header=NULL;
    750750    for(i=0;i<length;i++){
    751751      jsval tmp;
     
    753753      tmp1=JSValToChar(cx,&tmp);
    754754#ifdef ULINET_DEBUG
    755       curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1);
     755      curl_easy_setopt(handle->ihandle[handle->nb].handle,CURLOPT_VERBOSE,1);
    756756      fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
    757757#endif
    758       handle.header=curl_slist_append(handle.header, tmp1);
     758      handle->ihandle[handle->nb].header=curl_slist_append(handle->ihandle[handle->nb].header, tmp1);
    759759      free(tmp1);
    760760    }
     
    763763    fprintf(stderr,"not an array !!!!!!!\n");
    764764  }
    765   return handle;
     765  return *handle;
    766766}
    767767
     
    804804    url=JSValToChar(cx,argv);
    805805  }
     806  hInternet.waitingRequests[hInternet.nb]=strdup(url);
    806807  if(argc==4){
    807808    char *body;
     
    812813#endif
    813814    if(JS_IsArrayObject(cx,header))
    814       res1=setHeader(hInternet,cx,header);
     815      setHeader(&hInternet,cx,header);
    815816#ifdef ULINET_DEBUG
    816817    fprintf(stderr,"BODY (%s)\n",body);
    817818#endif
    818     res=InternetOpenUrl(res1,url,body,strlen(body),
    819                         INTERNET_FLAG_NO_CACHE_WRITE,0);   
     819    InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
     820                    INTERNET_FLAG_NO_CACHE_WRITE,0);   
     821    processDownloads(&hInternet);
    820822    free(body);
    821823  }else{
    822824    if(argc==3){
    823825      char *body=JSValToChar(cx,&argv[2]);
    824       res=InternetOpenUrl(hInternet,url,body,strlen(body),
    825                           INTERNET_FLAG_NO_CACHE_WRITE,0);
     826      InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
     827                      INTERNET_FLAG_NO_CACHE_WRITE,0);
     828      processDownloads(&hInternet);
    826829      free(body);
    827     }
    828     res=InternetOpenUrl(hInternet,url,NULL,0,
    829                         INTERNET_FLAG_NO_CACHE_WRITE,0);
    830   }
    831   tmpValue=(char*)malloc((res.nDataLen+1)*sizeof(char));
    832   InternetReadFile(res,(LPVOID)tmpValue,res.nDataLen,&dwRead);
     830    }else{
     831      InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0,
     832                      INTERNET_FLAG_NO_CACHE_WRITE,0);
     833      processDownloads(&hInternet);
     834    }
     835  }
     836  tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char));
     837  InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead);
    833838#ifdef ULINET_DEBUG
    834839  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
     
    846851  if(argc>=2)
    847852    free(method);
    848   if(argc==4 && res.header!=NULL){
    849     curl_slist_free_all(res.header);
    850   }
    851   InternetCloseHandle(hInternet);
     853  InternetCloseHandle(&hInternet);
    852854  JS_MaybeGC(cx);
    853855  return JS_TRUE;
  • trunk/zoo-project/zoo-kernel/service_internal_ms.c

    r490 r492  
    201201  }
    202202  addToMap(tmpI->content,"Reference",webService_url);
    203 
     203  free(webService_url);
    204204}
    205205
     
    255255              addToMap(output->content,"crs_isGeographic","false");
    256256          }
     257          free(proj4Str);
    257258        }
    258259        else{
     
    392393  FILE* file = fopen(pszDataSource, "rb");
    393394  FILE* fileZ = fopen(odsName, "wb");
     395  free(odsName);
    394396  fseek(file, 0, SEEK_END);
    395397  unsigned long fileLen=ftell(file);
     
    467469      i++;
    468470    }
    469 
    470   }
     471  }
     472  free(sdsName);
     473  free(dsName);
    471474
    472475  OGRDataSourceH poDS = NULL;
     
    568571      OSRExportToWkt(srs,&wkt);
    569572      setSrsInformations(output,m,myLayer,wkt);
     573      free(wkt);
    570574    }
    571575    else{
     
    937941  close(f);
    938942  addToMap(outputs->content,"storage",pszDataSource);
     943  free(pszDataSource);
    939944
    940945  /*
     
    10321037    cursor=cursor->next;
    10331038  }
     1039  freeMap(&correspondance);
     1040  free(correspondance);
    10341041
    10351042  /*
     
    10901097  sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
    10911098  msSaveMap(myMap,mapPath);
     1099  free(mapPath);
     1100  msGDALCleanup();
    10921101  msFreeMap(myMap);
    10931102}
  • trunk/zoo-project/zoo-kernel/ulinet.c

    r490 r492  
    3030#include "ulinet.h"
    3131#include <assert.h>
    32 
     32 
    3333size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data){
    3434  size_t realsize = size * nmemb;
    35   HINTERNET *psInternet;
     35  _HINTERNET *psInternet;
    3636  if(buffer==NULL){
    3737    buffer=NULL;
    3838    return -1;
    3939  }
    40   psInternet=(HINTERNET *)data;
     40  psInternet=(_HINTERNET *)data;
    4141  if(psInternet->pabyData){
    4242    psInternet->pabyData=(unsigned char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1);
     
    6464    char path[1024];
    6565    char domain[1024];
    66         char* tmp;
     66    char* tmp;
    6767    for(i=0;i<12;i++)
    6868#ifndef WIN32
     
    163163#endif
    164164
    165 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 
     165HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){
    166166  HINTERNET ret;
    167167  ret.handle=curl_multi_init();
    168   ret.ihandle=NULL;
    169   ret.hasCacheFile=0;
    170   ret.nDataAlloc = 0;
    171   ret.mimeType = NULL;
    172168  ret.agent=strdup(lpszAgent);
     169  ret.nb=0;
     170  ret.ihandle[ret.nb].header=NULL;
    173171  return ret;
    174172}
    175173
    176 void InternetCloseHandle(HINTERNET handle){
    177   if(handle.hasCacheFile>0){
    178     fclose(handle.file);
    179     unlink(handle.filename);
    180     handle.mimeType = NULL;
    181   }
    182   else{
    183     handle.pabyData = NULL;
    184     handle.mimeType = NULL;
    185     handle.nDataAlloc = handle.nDataLen = 0;
    186   }
    187   if(handle.ihandle!=NULL)
    188     curl_easy_cleanup(handle.ihandle);
    189   if(handle.handle)
    190     curl_multi_cleanup(handle.handle);
    191   free(handle.agent);
    192 }
    193 
    194 HINTERNET InternetOpenUrl(HINTERNET hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){
     174void InternetCloseHandle(HINTERNET* handle0){
     175  int i=0;
     176  for(i=0;i<handle0->nb;i++){
     177    _HINTERNET handle=handle0->ihandle[i];
     178    if(handle.hasCacheFile>0){
     179      fclose(handle.file);
     180      unlink(handle.filename);
     181      handle.mimeType = NULL;
     182    }
     183    else{
     184      handle.pabyData = NULL;
     185      handle.mimeType = NULL;
     186      handle.nDataAlloc = handle.nDataLen = 0;
     187    }
     188    if(handle0->ihandle[i].header!=NULL){
     189      curl_slist_free_all(handle0->ihandle[i].header);
     190      handle0->ihandle[i].header=NULL;
     191    }
     192    free(handle.mimeType);
     193  }
     194  if(handle0->handle)
     195    curl_multi_cleanup(handle0->handle);
     196  free(handle0->agent);
     197  for(i=handle0->nb-1;i>=0;i--){
     198    free(handle0->waitingRequests[i]);
     199  }
     200}
     201
     202HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){
    195203
    196204  char filename[255];
    197205  struct MemoryStruct header;
    198206
    199   hInternet.nDataLen = 0;
    200 
    201   hInternet.nDataAlloc = 0;
    202   hInternet.pabyData= NULL;
    203 
    204   if(hInternet.ihandle!=NULL)
    205     curl_easy_cleanup(hInternet.ihandle);
    206   hInternet.ihandle=curl_easy_init( );
    207   curl_easy_setopt(hInternet.ihandle, CURLOPT_COOKIEFILE, "ALL");
     207  hInternet->ihandle[hInternet->nb].handle=curl_easy_init( );
     208  hInternet->ihandle[hInternet->nb].hasCacheFile=0;
     209  hInternet->ihandle[hInternet->nb].nDataAlloc = 0;
     210  hInternet->ihandle[hInternet->nb].mimeType = NULL;
     211  hInternet->ihandle[hInternet->nb].nDataLen = 0;
     212  hInternet->ihandle[hInternet->nb].id = hInternet->nb;
     213  hInternet->ihandle[hInternet->nb].nDataAlloc = 0;
     214  hInternet->ihandle[hInternet->nb].pabyData = NULL;
     215
     216  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL");
    208217#ifndef TIGER
    209   curl_easy_setopt(hInternet.ihandle, CURLOPT_COOKIELIST, "ALL");
    210 #endif
    211   curl_easy_setopt(hInternet.ihandle, CURLOPT_USERAGENT, hInternet.agent);
    212  
    213   curl_easy_setopt(hInternet.ihandle,CURLOPT_FOLLOWLOCATION,1);
    214   curl_easy_setopt(hInternet.ihandle,CURLOPT_MAXREDIRS,3);
     218  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIELIST, "ALL");
     219#endif
     220  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_USERAGENT, hInternet->agent);
     221 
     222  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_FOLLOWLOCATION,1);
     223  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_MAXREDIRS,3);
    215224 
    216225  header.memory=NULL;
    217226  header.size = 0;
    218227
    219   curl_easy_setopt(hInternet.ihandle, CURLOPT_HEADERFUNCTION, header_write_data);
    220   curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEHEADER, (void *)&header);
    221 
    222 #ifdef MSG_LAF_VERBOSE
    223   curl_easy_setopt(hInternet.ihandle, CURLOPT_VERBOSE, 1);
     228  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_HEADERFUNCTION, header_write_data);
     229  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEHEADER, (void *)&header);
     230
     231#ifdef MSG_LAF_VERBOSE
     232  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_VERBOSE, 1);
    224233#endif
    225234
     
    227236  switch(dwFlags)
    228237    {
    229     case INTERNET_FLAG_NO_CACHE_WRITE:   
    230       hInternet.hasCacheFile=-1;
    231       curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEFUNCTION, write_data_into);
    232       curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEDATA, &hInternet);
     238    case INTERNET_FLAG_NO_CACHE_WRITE:
     239      hInternet->ihandle[hInternet->nb].hasCacheFile=-1;
     240      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, write_data_into);
     241      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, (void*)&hInternet->ihandle[hInternet->nb]);
    233242      break;
    234243    default:
    235       sprintf(filename,"/tmp/ZOO_Cache%d",(int)time(NULL));
    236       filename[24]=0;
    237 #ifdef MSG_LAF_VERBOSE
    238       fprintf(stderr,"file=%s",filename);
    239 #endif
    240       hInternet.filename=filename;
    241       hInternet.file=fopen(hInternet.filename,"w+");
     244      sprintf(hInternet->ihandle[hInternet->nb].filename,"/tmp/ZOO_Cache%d",(int)time(NULL));
     245      hInternet->ihandle[hInternet->nb].filename[24]=0;
     246#ifdef MSG_LAF_VERBOSE
     247      fprintf(stderr,"file=%s",hInternet->ihandle[hInternet->nb].filename);
     248#endif
     249      hInternet->ihandle[hInternet->nb].filename=filename;
     250      hInternet->ihandle[hInternet->nb].file=fopen(hInternet->ihandle[hInternet->nb].filename,"w+");
    242251   
    243       hInternet.hasCacheFile=1;
    244       curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEFUNCTION, NULL);
    245       curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEDATA, hInternet.file);
    246       hInternet.nDataLen=0;
     252      hInternet->ihandle[hInternet->nb].hasCacheFile=1;
     253      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEFUNCTION, NULL);
     254      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEDATA, hInternet->ihandle[hInternet->nb].file);
     255      hInternet->ihandle[hInternet->nb].nDataLen=0;
    247256      break;
    248257    }
     
    255264    fprintf(stderr,"HEADER : %s\n",lpszHeaders);
    256265#endif
    257     //curl_easy_setopt(hInternet.handle,CURLOPT_COOKIE,lpszHeaders);
    258     curl_easy_setopt(hInternet.ihandle,CURLOPT_POST,1);
     266    curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POST,1);
    259267#ifdef ULINET_DEBUG
    260268    fprintf(stderr,"** (%s) %d **\n",lpszHeaders,dwHeadersLength);
    261     curl_easy_setopt(hInternet.ihandle,CURLOPT_VERBOSE,1);
    262 #endif
    263     curl_easy_setopt(hInternet.ihandle,CURLOPT_POSTFIELDS,lpszHeaders);
    264     //curl_easy_setopt(hInternet.handle,CURLOPT_POSTFIELDSIZE,dwHeadersLength+1);
    265     if(hInternet.header!=NULL)
    266       curl_easy_setopt(hInternet.ihandle,CURLOPT_HTTPHEADER,hInternet.header);
    267   }
    268 
    269   curl_easy_setopt(hInternet.ihandle,CURLOPT_URL,lpszUrl);
    270 
    271   curl_multi_add_handle(hInternet.handle,hInternet.ihandle);
    272  
    273   int still_running=0;
    274   int msgs_left=0;
    275   do{
    276     curl_multi_perform(hInternet.handle, &still_running);
    277   }while(still_running);
    278 
    279   CURLMsg *msg=NULL;
    280   while ((msg = curl_multi_info_read(hInternet.handle, &msgs_left))) {
    281     if (msg->msg == CURLMSG_DONE) {
    282       CURL *eh=NULL;
    283       eh = msg->easy_handle;
    284       curl_easy_getinfo(eh,CURLINFO_CONTENT_TYPE,&hInternet.mimeType);
    285     }
    286     else {
    287       fprintf(stderr, "error: after curl_multi_info_read(), CURLMsg=%d\n", msg->msg);
    288     }
    289   }
    290   curl_multi_remove_handle(hInternet.handle, hInternet.ihandle);
     269    curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_VERBOSE,1);
     270#endif
     271    curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,lpszHeaders);
     272    //curl_easy_setopt(hInternet->handle,CURLOPT_POSTFIELDSIZE,dwHeadersLength+1);
     273    if(hInternet->ihandle[hInternet->nb].header!=NULL)
     274      curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_HTTPHEADER,hInternet->ihandle[hInternet->nb].header);
     275  }
     276
     277  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl);
     278
     279  curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle);
     280 
     281  ++hInternet->nb;
     282  hInternet->ihandle[hInternet->nb].header=NULL;
    291283
    292284#ifdef ULINET_DEBUG
     
    294286  fflush(stderr);
    295287#endif
    296   return hInternet;
     288  return *hInternet;
    297289};
    298290
     291int processDownloads(HINTERNET* hInternet){
     292  int still_running=0;
     293  int msgs_left=0;
     294  int i=0;
     295  do{
     296    curl_multi_perform(hInternet->handle, &still_running);
     297  }while(still_running); 
     298  for(i=0;i<hInternet->nb;i++){
     299    curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&hInternet->ihandle[i].mimeType);
     300    curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle);
     301    curl_easy_cleanup(hInternet->ihandle[i].handle);
     302  }
     303}
     304
    299305int freeCookieList(HINTERNET hInternet){
    300   memset(&CCookie[0],0,1024);
     306  memset(&CCookie[hInternet.nb][0],0,1024);
    301307#ifndef TIGER
    302   curl_easy_setopt(hInternet.ihandle, CURLOPT_COOKIELIST, "ALL");
     308  curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL");
    303309#endif
    304310  return 1;
    305311}
    306312
    307 int InternetReadFile(HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){
     313int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){
    308314  int dwDataSize;
    309315
     
    338344  }
    339345
    340   CCookie[0]=0;
     346  CCookie[hInternet.id][0]=0;
    341347
    342348  if( *lpdwNumberOfBytesRead < dwDataSize )
     
    346352}
    347353
    348 bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize){
    349 
    350   bool ret=1; 
    351   int count=0;
    352   int hasCookie=-1;
    353   char TMP[1024];
    354   int j;
    355   int tmpC=0;
    356   lpszUrl=NULL;
    357 
    358   for(j=0;j<strlen(CCookie);j++){
    359     if(lpszCookieName[count]==CCookie[j]){
    360       hasCookie=1;
    361       count++;
    362       if(count==strlen(lpszCookieName))
    363         break;
    364       continue;
    365     }
    366   }
    367 
    368   if(hasCookie>0){
    369     if(CCookie[count]=='='){
    370       int i=0;
    371       count++;
    372       for(i=count;i<strlen(CCookie);i++){
    373         if(CCookie[i]!=';'){
    374           TMP[tmpC]=CCookie[i];
    375           tmpC++;
    376         }
    377         else{
    378           break;
    379         }
    380       }
    381     }
    382   }
    383   else
    384     return -1;
    385 
    386   TMP[tmpC]=0;
    387   strncpy(lpszCookieData,TMP,strlen(TMP)+1);
    388   lpdwSize=(size_t*) strlen(lpszCookieData);
    389 
    390 #ifdef MSG_LAF_VERBOSE
    391   printf("Cookie returned : (%s)",(char*)lpszCookieData);
    392 #endif
    393 
    394   return ret;
    395 
    396 }
    397 
  • trunk/zoo-project/zoo-kernel/ulinet.h

    r490 r492  
    2727
    2828#include "fcgi_stdio.h"
     29#include "service.h"
    2930#include <stdlib.h>
    3031#include <fcntl.h>
     
    4445#endif
    4546
     47#define MAX_REQ 100
    4648
    4749#ifdef _ULINET
    48 static char CCookie[1024];
     50static char CCookie[MAX_REQ][1024];
    4951#else
    50 extern char HEADER[3072];
    51 extern char CCookie[1024];
     52extern char HEADER[MAX_REQ][3072];
     53extern char CCookie[MAX_REQ][1024];
    5254#endif
    5355
     
    5860  //static pthread_mutex_t hMutexConnect = PTHREAD_MUTEX_INITIALIZER;
    5961
     62static char* waitingRequests[MAX_REQ];
     63
    6064struct MemoryStruct {
    6165  char *memory;
     
    6468
    6569typedef struct {
    66   CURLM *handle;
    67   CURL *ihandle;
     70  CURL *handle;
    6871  struct curl_slist *header;
    6972  char* filename;
    70   char *agent;
    7173  FILE* file;
    7274  size_t size;
     75  unsigned char *pabyData;
     76  unsigned char *mimeType;
    7377  int hasCacheFile;
    7478  int nDataLen;
    7579  int nDataAlloc;
    76   unsigned char *pabyData;
    77   unsigned char *mimeType;
     80  int id;
     81} _HINTERNET;
     82
     83typedef struct {
     84  CURLM *handle;
     85  _HINTERNET ihandle[MAX_REQ];
     86  char *waitingRequests[MAX_REQ];
     87  char *agent;
     88  int nb;
    7889} HINTERNET;
    7990
     
    112123HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags);
    113124
    114 void InternetCloseHandle(HINTERNET handle);
     125void InternetCloseHandle(HINTERNET* handle);
    115126
    116127#define INTERNET_FLAG_EXISTING_CONNECT         0
     
    137148#  define CHECK_INET_HANDLE(h) (h.handle != 0)
    138149
    139 HINTERNET InternetOpenUrl(HINTERNET hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext);
     150HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext);
     151
     152int processDownloads(HINTERNET* hInternet);
    140153
    141154int freeCookieList(HINTERNET hInternet);
    142155
    143 int InternetReadFile(HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead);
    144 
    145 bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize);
     156int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead);
    146157
    147158#ifdef __cplusplus
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r490 r492  
    257257#endif
    258258        t=readServiceFile(m,tmps1,&s1,dp->d_name);
     259
    259260        if(t<0){
    260261          dumpMaps(m);
     
    961962        char buff1[1024];
    962963        while(tmps!=NULL){
     964          int hasVal=-1;
    963965          char *corig=strdup(tmps);
    964966          if(strstr(corig,".")!=NULL){
     
    966968            s1=(service*)malloc(SERVICE_SIZE);
    967969            t=readServiceFile(m,buff1,&s1,corig);
     970
    968971            if(t<0){
    969972              map* tmp00=getMapFromMaps(m,"lenv","message");
     
    977980              freeMaps(&m);
    978981              free(m);
     982              free(REQUEST);
    979983              return 1;
    980984            }
     
    989993            setMapInMaps(m,"lenv","level","0");
    990994          }
    991           free(corig);
    992995         
    993996          memset(buff,0,256);
    994           snprintf(buff,256,"%s.zcfg",tmps);
     997          snprintf(buff,256,"%s.zcfg",corig);
     998          free(corig);
    995999          memset(buff1,0,1024);
    9961000#ifdef DEBUG
    9971001          printf("\n#######%s\n########\n",buff);
    9981002#endif
    999           while ((dp = readdir(dirp)) != NULL)
    1000             if( (strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0)
    1001                 || strcasecmp(dp->d_name,buff)==0 ){
     1003          while ((dp = readdir(dirp)) != NULL){
     1004            if( strcasecmp(dp->d_name,buff)==0 ){
    10021005              memset(buff1,0,1024);
    10031006              snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
     
    10251028                freeMaps(&m);
    10261029                free(m);
     1030                free(orig);
     1031                free(REQUEST);
     1032                closedir(dirp);
     1033                xmlFreeDoc(doc);
    10271034                return 1;
    10281035              }
     
    10351042              s1=NULL;
    10361043              scount++;
     1044              hasVal=1;
    10371045            }
     1046          }
     1047          if(hasVal<0){
     1048            map* tmp00=getMapFromMaps(m,"lenv","message");
     1049            char tmp01[1024];
     1050            if(tmp00!=NULL)
     1051              sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),buff,tmp00->value);
     1052            else
     1053              sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),buff);
     1054            dup2(saved_stdout,fileno(stdout));
     1055            errorException(m, tmp01,"InvalidParameterValue","Identifier");
     1056            freeMaps(&m);
     1057            free(m);
     1058            free(orig);
     1059            free(REQUEST);
     1060            closedir(dirp);
     1061            xmlFreeDoc(doc);
     1062            return 1;
     1063          }
    10381064          rewinddir(dirp);
    10391065          tmps=strtok_r(NULL,",",&saveptr);
     
    12711297      free(REQUEST);
    12721298      free(SERVICE_URL);
    1273       InternetCloseHandle(hInternet);
     1299      InternetCloseHandle(&hInternet);
    12741300      freeService(&s1);
    12751301      free(s1);
     
    13991425                free(REQUEST);
    14001426                free(SERVICE_URL);
    1401                 InternetCloseHandle(hInternet);
     1427                InternetCloseHandle(&hInternet);
    14021428                freeService(&s1);
    14031429                free(s1);
     
    14071433              fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
    14081434#endif
    1409               addToMap(tmpmaps->content,tmpn1,tmpx2);
    1410              
     1435              addToMap(tmpmaps->content,tmpn1,tmpx2);         
    14111436#ifndef WIN32
    14121437              if(CHECK_INET_HANDLE(hInternet))
    14131438#endif
    14141439                {
    1415                   if(loadRemoteFile(&m,&tmpmaps->content,hInternet,tmpx2)<0){
     1440                  if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,tmpx2)<0){
    14161441                    freeMaps(&m);
    14171442                    free(m);
    14181443                    free(REQUEST);
    14191444                    free(SERVICE_URL);
    1420                     InternetCloseHandle(hInternet);
     1445                    InternetCloseHandle(&hInternet);
    14211446                    freeService(&s1);
    14221447                    free(s1);
     
    14451470                free(REQUEST);
    14461471                free(SERVICE_URL);
    1447                 InternetCloseHandle(hInternet);
     1472                InternetCloseHandle(&hInternet);
    14481473                freeService(&s1);
    14491474                free(s1);
     
    15751600                  if(!(ltmp!=NULL && strncmp(ltmp->value,"POST",4)==0)
    15761601                     && CHECK_INET_HANDLE(hInternet)){
    1577                     if(loadRemoteFile(&m,&tmpmaps->content,hInternet,(char*)val)!=0){
     1602                    if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,(char*)val)!=0){
    15781603                      freeMaps(&m);
    15791604                      free(m);
    15801605                      free(REQUEST);
    15811606                      free(SERVICE_URL);
    1582                       InternetCloseHandle(hInternet);
     1607                      InternetCloseHandle(&hInternet);
    15831608                      freeService(&s1);
    15841609                      free(s1);
     
    15971622#endif
    15981623            xmlNodePtr cur3=cur2->children;
    1599             HINTERNET hInternetP;
     1624            /*      HINTERNET hInternetP;
    16001625            hInternetP=InternetOpen(
    16011626#ifndef WIN32
     
    16041629                                   "ZooWPSClient\0",
    16051630                                   INTERNET_OPEN_TYPE_PRECONFIG,
    1606                                    NULL,NULL, 0);
    1607             hInternetP.header=NULL;
     1631                                   NULL,NULL, 0);*/
     1632            //hInternet.ihandle[hInternet.nb].header=NULL;
    16081633            while(cur3!=NULL){
    16091634              while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE)
     
    16381663                  xmlFree(val);
    16391664                }
    1640                 hInternetP.header=curl_slist_append(hInternetP.header, has);
     1665                hInternet.ihandle[hInternet.nb].header=curl_slist_append(hInternet.ihandle[hInternet.nb].header, has);
    16411666                if(has!=NULL)
    16421667                  free(has);
     
    16751700#ifdef POST_DEBUG
    16761701                    fprintf(stderr,"%s %s\n",btmp->value,tmp);
    1677                     curl_easy_setopt(hInternetP.handle, CURLOPT_VERBOSE, 1);
    1678 #endif
    1679                     res=InternetOpenUrl(hInternetP,btmp->value,tmp,strlen(tmp),
     1702                    curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
     1703#endif
     1704                    hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
     1705                    InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],strlen(hInternet.waitingRequests[hInternet.nb]),
    16801706                                        INTERNET_FLAG_NO_CACHE_WRITE,0);
    1681                     char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char));
    1682                     if(tmpContent == NULL){
    1683                       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1684                     }
    1685                     size_t dwRead;
    1686                     InternetReadFile(res, (LPVOID)tmpContent,
    1687                                      res.nDataLen, &dwRead);
    1688                     tmpContent[res.nDataLen]=0;
    1689                     if(hInternetP.header!=NULL)
    1690                       curl_slist_free_all(hInternetP.header);
    1691                     addToMap(tmpmaps->content,"value",tmpContent);
    1692                     free(tmpContent);
    1693 #ifdef POST_DEBUG
    1694                     fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
    1695 #endif             
    16961707                  }
    16971708                  free(tmp);
     
    17081719                                           INTERNET_OPEN_TYPE_PRECONFIG,
    17091720                                           NULL,NULL, 0);
    1710                     if(!CHECK_INET_HANDLE(bInternet))
     1721                    if(!CHECK_INET_HANDLE(hInternet))
    17111722                      fprintf(stderr,"WARNING : hInternet handle failed to initialize");
    17121723#ifdef POST_DEBUG
    17131724                    curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
    17141725#endif
    1715                     res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
     1726                    bInternet.waitingRequests[0]=strdup((char*)val);
     1727                    res1=InternetOpenUrl(&bInternet,bInternet.waitingRequests[0],NULL,0,
    17161728                                         INTERNET_FLAG_NO_CACHE_WRITE,0);
     1729                    processDownloads(&bInternet);
    17171730                    char* tmp=
    1718                       (char*)malloc((res1.nDataLen+1)*sizeof(char));
     1731                      (char*)malloc((bInternet.ihandle[0].nDataLen+1)*sizeof(char));
    17191732                    if(tmp == NULL){
    17201733                      return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    17211734                    }
    17221735                    size_t bRead;
    1723                     InternetReadFile(res1, (LPVOID)tmp,
    1724                                      res1.nDataLen, &bRead);
    1725                     tmp[res1.nDataLen]=0;
    1726                     InternetCloseHandle(bInternet);
     1736                    InternetReadFile(bInternet.ihandle[0], (LPVOID)tmp,
     1737                                     bInternet.ihandle[0].nDataLen, &bRead);
     1738                    tmp[bInternet.ihandle[0].nDataLen]=0;
     1739                    InternetCloseHandle(&bInternet);
    17271740                    map *btmp=getMap(tmpmaps->content,"href");
    17281741                    if(btmp!=NULL){
    17291742#ifdef POST_DEBUG
    17301743                      fprintf(stderr,"%s %s\n",btmp->value,tmp);
    1731                       curl_easy_setopt(hInternetP.handle, CURLOPT_VERBOSE, 1);
    1732 #endif
    1733                       res=InternetOpenUrl(hInternetP,btmp->value,tmp,
    1734                                           strlen(tmp),
     1744#endif
     1745                      hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
     1746                      res=InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],
     1747                                          strlen(hInternet.waitingRequests[hInternet.nb]),
    17351748                                          INTERNET_FLAG_NO_CACHE_WRITE,0);
    1736                       char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char));
    1737                       if(tmpContent == NULL){
    1738                         return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1739                       }
    1740                       size_t dwRead;
    1741                       InternetReadFile(res, (LPVOID)tmpContent,
    1742                                        res.nDataLen, &dwRead);
    1743                       tmpContent[res.nDataLen]=0;
    1744                       if(hInternetP.header!=NULL)
    1745                         curl_slist_free_all(hInternetP.header);
    1746                       addToMap(tmpmaps->content,"value",tmpContent);
    1747 #ifdef POST_DEBUG
    1748                       fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
    1749 #endif
    17501749                    }
     1750                    free(tmp);
    17511751                  }
    17521752              }
    17531753              cur3=cur3->next;
    17541754            }
    1755             InternetCloseHandle(hInternetP);
    17561755#ifdef POST_DEBUG
    17571756            fprintf(stderr,"Header and Body was parsed from Reference \n");
     
    19011900                free(REQUEST);
    19021901                free(SERVICE_URL);
    1903                 InternetCloseHandle(hInternet);
     1902                InternetCloseHandle(&hInternet);
    19041903                freeService(&s1);
    19051904                free(s1);
     
    21482147  }
    21492148 
     2149  runHttpRequests(&m,&request_input_real_format,&hInternet);
    21502150
    21512151  //  if(CHECK_INET_HANDLE(hInternet))
    2152   InternetCloseHandle(hInternet);
     2152  InternetCloseHandle(&hInternet);
    21532153
    21542154#ifdef DEBUG
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