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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
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