Changeset 492 for trunk/zoo-project
- Timestamp:
- Jul 11, 2014, 10:14:03 PM (10 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/HISTORY.txt
r485 r492 1 1 Version 1.4.0-dev 2 * Inputs passed by reference downloaded in parallel 3 * Conform behavior for DescribeProcess when the Identifier was not found 2 4 * Add support of maximumMegabytes keywords for ComplexData Inputs 3 5 * Add the optional YAML ZCFG support #4 and the zcfg2yaml converter -
trunk/zoo-project/zoo-kernel/service_internal.c
r490 r492 1871 1871 if(testMap!=NULL){ 1872 1872 HINTERNET hInternet; 1873 char* tmpValue; 1874 size_t dwRead; 1873 1875 hInternet=InternetOpen( 1874 1876 #ifndef WIN32 … … 1879 1881 NULL,NULL, 0); 1880 1882 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); 1883 1888 } 1884 1889 #endif … … 1963 1968 else 1964 1969 #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); 1966 1974 } 1967 1975 tmp=tmp->next; … … 2872 2880 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 2873 2881 #endif 2874 fwrite(mimeType, 1,strlen(mimeType),fo);2882 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 2875 2883 fclose(fo); 2876 2884 … … 2901 2909 } 2902 2910 2911 int 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 2903 2960 /** 2904 2961 * loadRemoteFile: 2905 2962 * Try to load file from cache or download a remote file if not in cache 2906 2963 */ 2907 int loadRemoteFile(maps** m,map** content,HINTERNET hInternet,char *url){ 2908 HINTERNET res; 2964 int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){ 2909 2965 char* fcontent; 2910 2966 char* cached=isInCache(*m,url); … … 2932 2988 } 2933 2989 }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; 2944 2993 } 2945 2994 if(fsize==0){ 2946 2995 return errorException(*m, _("Unable to download the file."), "InternalError",NULL); 2947 2996 } 2948 2949 2997 if(mimeType!=NULL){ 2950 2998 addToMap(*content,"fmimeType",mimeType); … … 2957 3005 if(tmpMap->value==NULL) 2958 3006 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 2959 //snprintf(tmpMap->value,(fsize+1)*sizeof(char),fcontent);2960 3007 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 2961 3008 … … 2965 3012 if(cached==NULL) 2966 3013 addToCache(*m,url,fcontent,mimeType,fsize); 3014 else 3015 addToMap(*content,"isCached","true"); 2967 3016 free(fcontent); 2968 3017 free(mimeType); -
trunk/zoo-project/zoo-kernel/service_internal.h
r490 r492 148 148 void addToCache(maps*,char*,char*,char*,int); 149 149 char* isInCache(maps*,char*); 150 int loadRemoteFile(maps**,map**,HINTERNET,char*); 150 int runHttpRequests(maps**,maps**,HINTERNET*); 151 int loadRemoteFile(maps**,map**,HINTERNET*,char*); 151 152 152 153 char *readVSIFile(maps*,const char*); -
trunk/zoo-project/zoo-kernel/service_internal_js.c
r471 r492 732 732 } 733 733 734 HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){734 HINTERNET setHeader(HINTERNET* handle,JSContext *cx,JSObject *header){ 735 735 jsuint length=0; 736 736 jsint i=0; … … 747 747 fprintf(stderr,"header is an array of %d elements\n",length); 748 748 #endif 749 handle .header=NULL;749 handle->ihandle[handle->nb].header=NULL; 750 750 for(i=0;i<length;i++){ 751 751 jsval tmp; … … 753 753 tmp1=JSValToChar(cx,&tmp); 754 754 #ifdef ULINET_DEBUG 755 curl_easy_setopt(handle .handle,CURLOPT_VERBOSE,1);755 curl_easy_setopt(handle->ihandle[handle->nb].handle,CURLOPT_VERBOSE,1); 756 756 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 757 757 #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); 759 759 free(tmp1); 760 760 } … … 763 763 fprintf(stderr,"not an array !!!!!!!\n"); 764 764 } 765 return handle;765 return *handle; 766 766 } 767 767 … … 804 804 url=JSValToChar(cx,argv); 805 805 } 806 hInternet.waitingRequests[hInternet.nb]=strdup(url); 806 807 if(argc==4){ 807 808 char *body; … … 812 813 #endif 813 814 if(JS_IsArrayObject(cx,header)) 814 res1=setHeader(hInternet,cx,header);815 setHeader(&hInternet,cx,header); 815 816 #ifdef ULINET_DEBUG 816 817 fprintf(stderr,"BODY (%s)\n",body); 817 818 #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); 820 822 free(body); 821 823 }else{ 822 824 if(argc==3){ 823 825 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); 826 829 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); 833 838 #ifdef ULINET_DEBUG 834 839 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue); … … 846 851 if(argc>=2) 847 852 free(method); 848 if(argc==4 && res.header!=NULL){ 849 curl_slist_free_all(res.header); 850 } 851 InternetCloseHandle(hInternet); 853 InternetCloseHandle(&hInternet); 852 854 JS_MaybeGC(cx); 853 855 return JS_TRUE; -
trunk/zoo-project/zoo-kernel/service_internal_ms.c
r490 r492 201 201 } 202 202 addToMap(tmpI->content,"Reference",webService_url); 203 203 free(webService_url); 204 204 } 205 205 … … 255 255 addToMap(output->content,"crs_isGeographic","false"); 256 256 } 257 free(proj4Str); 257 258 } 258 259 else{ … … 392 393 FILE* file = fopen(pszDataSource, "rb"); 393 394 FILE* fileZ = fopen(odsName, "wb"); 395 free(odsName); 394 396 fseek(file, 0, SEEK_END); 395 397 unsigned long fileLen=ftell(file); … … 467 469 i++; 468 470 } 469 470 } 471 } 472 free(sdsName); 473 free(dsName); 471 474 472 475 OGRDataSourceH poDS = NULL; … … 568 571 OSRExportToWkt(srs,&wkt); 569 572 setSrsInformations(output,m,myLayer,wkt); 573 free(wkt); 570 574 } 571 575 else{ … … 937 941 close(f); 938 942 addToMap(outputs->content,"storage",pszDataSource); 943 free(pszDataSource); 939 944 940 945 /* … … 1032 1037 cursor=cursor->next; 1033 1038 } 1039 freeMap(&correspondance); 1040 free(correspondance); 1034 1041 1035 1042 /* … … 1090 1097 sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value); 1091 1098 msSaveMap(myMap,mapPath); 1099 free(mapPath); 1100 msGDALCleanup(); 1092 1101 msFreeMap(myMap); 1093 1102 } -
trunk/zoo-project/zoo-kernel/ulinet.c
r490 r492 30 30 #include "ulinet.h" 31 31 #include <assert.h> 32 32 33 33 size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data){ 34 34 size_t realsize = size * nmemb; 35 HINTERNET *psInternet;35 _HINTERNET *psInternet; 36 36 if(buffer==NULL){ 37 37 buffer=NULL; 38 38 return -1; 39 39 } 40 psInternet=( HINTERNET *)data;40 psInternet=(_HINTERNET *)data; 41 41 if(psInternet->pabyData){ 42 42 psInternet->pabyData=(unsigned char*)realloc(psInternet->pabyData,psInternet->nDataLen+realsize+1); … … 64 64 char path[1024]; 65 65 char domain[1024]; 66 66 char* tmp; 67 67 for(i=0;i<12;i++) 68 68 #ifndef WIN32 … … 163 163 #endif 164 164 165 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 165 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 166 166 HINTERNET ret; 167 167 ret.handle=curl_multi_init(); 168 ret.ihandle=NULL;169 ret.hasCacheFile=0;170 ret.nDataAlloc = 0;171 ret.mimeType = NULL;172 168 ret.agent=strdup(lpszAgent); 169 ret.nb=0; 170 ret.ihandle[ret.nb].header=NULL; 173 171 return ret; 174 172 } 175 173 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){ 174 void 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 202 HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){ 195 203 196 204 char filename[255]; 197 205 struct MemoryStruct header; 198 206 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"); 208 217 #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); 215 224 216 225 header.memory=NULL; 217 226 header.size = 0; 218 227 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); 224 233 #endif 225 234 … … 227 236 switch(dwFlags) 228 237 { 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]); 233 242 break; 234 243 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+"); 242 251 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; 247 256 break; 248 257 } … … 255 264 fprintf(stderr,"HEADER : %s\n",lpszHeaders); 256 265 #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); 259 267 #ifdef ULINET_DEBUG 260 268 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; 291 283 292 284 #ifdef ULINET_DEBUG … … 294 286 fflush(stderr); 295 287 #endif 296 return hInternet;288 return *hInternet; 297 289 }; 298 290 291 int 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 299 305 int freeCookieList(HINTERNET hInternet){ 300 memset(&CCookie[ 0],0,1024);306 memset(&CCookie[hInternet.nb][0],0,1024); 301 307 #ifndef TIGER 302 curl_easy_setopt(hInternet.ihandle , CURLOPT_COOKIELIST, "ALL");308 curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL"); 303 309 #endif 304 310 return 1; 305 311 } 306 312 307 int InternetReadFile( HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){313 int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){ 308 314 int dwDataSize; 309 315 … … 338 344 } 339 345 340 CCookie[ 0]=0;346 CCookie[hInternet.id][0]=0; 341 347 342 348 if( *lpdwNumberOfBytesRead < dwDataSize ) … … 346 352 } 347 353 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 else384 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_VERBOSE391 printf("Cookie returned : (%s)",(char*)lpszCookieData);392 #endif393 394 return ret;395 396 }397 -
trunk/zoo-project/zoo-kernel/ulinet.h
r490 r492 27 27 28 28 #include "fcgi_stdio.h" 29 #include "service.h" 29 30 #include <stdlib.h> 30 31 #include <fcntl.h> … … 44 45 #endif 45 46 47 #define MAX_REQ 100 46 48 47 49 #ifdef _ULINET 48 static char CCookie[ 1024];50 static char CCookie[MAX_REQ][1024]; 49 51 #else 50 extern char HEADER[ 3072];51 extern char CCookie[ 1024];52 extern char HEADER[MAX_REQ][3072]; 53 extern char CCookie[MAX_REQ][1024]; 52 54 #endif 53 55 … … 58 60 //static pthread_mutex_t hMutexConnect = PTHREAD_MUTEX_INITIALIZER; 59 61 62 static char* waitingRequests[MAX_REQ]; 63 60 64 struct MemoryStruct { 61 65 char *memory; … … 64 68 65 69 typedef struct { 66 CURLM *handle; 67 CURL *ihandle; 70 CURL *handle; 68 71 struct curl_slist *header; 69 72 char* filename; 70 char *agent;71 73 FILE* file; 72 74 size_t size; 75 unsigned char *pabyData; 76 unsigned char *mimeType; 73 77 int hasCacheFile; 74 78 int nDataLen; 75 79 int nDataAlloc; 76 unsigned char *pabyData; 77 unsigned char *mimeType; 80 int id; 81 } _HINTERNET; 82 83 typedef struct { 84 CURLM *handle; 85 _HINTERNET ihandle[MAX_REQ]; 86 char *waitingRequests[MAX_REQ]; 87 char *agent; 88 int nb; 78 89 } HINTERNET; 79 90 … … 112 123 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags); 113 124 114 void InternetCloseHandle(HINTERNET handle);125 void InternetCloseHandle(HINTERNET* handle); 115 126 116 127 #define INTERNET_FLAG_EXISTING_CONNECT 0 … … 137 148 # define CHECK_INET_HANDLE(h) (h.handle != 0) 138 149 139 HINTERNET InternetOpenUrl(HINTERNET hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext); 150 HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext); 151 152 int processDownloads(HINTERNET* hInternet); 140 153 141 154 int freeCookieList(HINTERNET hInternet); 142 155 143 int InternetReadFile(HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead); 144 145 bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize); 156 int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead,size_t *lpdwNumberOfBytesRead); 146 157 147 158 #ifdef __cplusplus -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r490 r492 257 257 #endif 258 258 t=readServiceFile(m,tmps1,&s1,dp->d_name); 259 259 260 if(t<0){ 260 261 dumpMaps(m); … … 961 962 char buff1[1024]; 962 963 while(tmps!=NULL){ 964 int hasVal=-1; 963 965 char *corig=strdup(tmps); 964 966 if(strstr(corig,".")!=NULL){ … … 966 968 s1=(service*)malloc(SERVICE_SIZE); 967 969 t=readServiceFile(m,buff1,&s1,corig); 970 968 971 if(t<0){ 969 972 map* tmp00=getMapFromMaps(m,"lenv","message"); … … 977 980 freeMaps(&m); 978 981 free(m); 982 free(REQUEST); 979 983 return 1; 980 984 } … … 989 993 setMapInMaps(m,"lenv","level","0"); 990 994 } 991 free(corig);992 995 993 996 memset(buff,0,256); 994 snprintf(buff,256,"%s.zcfg",tmps); 997 snprintf(buff,256,"%s.zcfg",corig); 998 free(corig); 995 999 memset(buff1,0,1024); 996 1000 #ifdef DEBUG 997 1001 printf("\n#######%s\n########\n",buff); 998 1002 #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 ){ 1002 1005 memset(buff1,0,1024); 1003 1006 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); … … 1025 1028 freeMaps(&m); 1026 1029 free(m); 1030 free(orig); 1031 free(REQUEST); 1032 closedir(dirp); 1033 xmlFreeDoc(doc); 1027 1034 return 1; 1028 1035 } … … 1035 1042 s1=NULL; 1036 1043 scount++; 1044 hasVal=1; 1037 1045 } 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 } 1038 1064 rewinddir(dirp); 1039 1065 tmps=strtok_r(NULL,",",&saveptr); … … 1271 1297 free(REQUEST); 1272 1298 free(SERVICE_URL); 1273 InternetCloseHandle( hInternet);1299 InternetCloseHandle(&hInternet); 1274 1300 freeService(&s1); 1275 1301 free(s1); … … 1399 1425 free(REQUEST); 1400 1426 free(SERVICE_URL); 1401 InternetCloseHandle( hInternet);1427 InternetCloseHandle(&hInternet); 1402 1428 freeService(&s1); 1403 1429 free(s1); … … 1407 1433 fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1); 1408 1434 #endif 1409 addToMap(tmpmaps->content,tmpn1,tmpx2); 1410 1435 addToMap(tmpmaps->content,tmpn1,tmpx2); 1411 1436 #ifndef WIN32 1412 1437 if(CHECK_INET_HANDLE(hInternet)) 1413 1438 #endif 1414 1439 { 1415 if(loadRemoteFile(&m,&tmpmaps->content, hInternet,tmpx2)<0){1440 if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,tmpx2)<0){ 1416 1441 freeMaps(&m); 1417 1442 free(m); 1418 1443 free(REQUEST); 1419 1444 free(SERVICE_URL); 1420 InternetCloseHandle( hInternet);1445 InternetCloseHandle(&hInternet); 1421 1446 freeService(&s1); 1422 1447 free(s1); … … 1445 1470 free(REQUEST); 1446 1471 free(SERVICE_URL); 1447 InternetCloseHandle( hInternet);1472 InternetCloseHandle(&hInternet); 1448 1473 freeService(&s1); 1449 1474 free(s1); … … 1575 1600 if(!(ltmp!=NULL && strncmp(ltmp->value,"POST",4)==0) 1576 1601 && CHECK_INET_HANDLE(hInternet)){ 1577 if(loadRemoteFile(&m,&tmpmaps->content, hInternet,(char*)val)!=0){1602 if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,(char*)val)!=0){ 1578 1603 freeMaps(&m); 1579 1604 free(m); 1580 1605 free(REQUEST); 1581 1606 free(SERVICE_URL); 1582 InternetCloseHandle( hInternet);1607 InternetCloseHandle(&hInternet); 1583 1608 freeService(&s1); 1584 1609 free(s1); … … 1597 1622 #endif 1598 1623 xmlNodePtr cur3=cur2->children; 1599 HINTERNET hInternetP;1624 /* HINTERNET hInternetP; 1600 1625 hInternetP=InternetOpen( 1601 1626 #ifndef WIN32 … … 1604 1629 "ZooWPSClient\0", 1605 1630 INTERNET_OPEN_TYPE_PRECONFIG, 1606 NULL,NULL, 0); 1607 hInternetP.header=NULL;1631 NULL,NULL, 0);*/ 1632 //hInternet.ihandle[hInternet.nb].header=NULL; 1608 1633 while(cur3!=NULL){ 1609 1634 while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE) … … 1638 1663 xmlFree(val); 1639 1664 } 1640 hInternet P.header=curl_slist_append(hInternetP.header, has);1665 hInternet.ihandle[hInternet.nb].header=curl_slist_append(hInternet.ihandle[hInternet.nb].header, has); 1641 1666 if(has!=NULL) 1642 1667 free(has); … … 1675 1700 #ifdef POST_DEBUG 1676 1701 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]), 1680 1706 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_DEBUG1694 fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);1695 #endif1696 1707 } 1697 1708 free(tmp); … … 1708 1719 INTERNET_OPEN_TYPE_PRECONFIG, 1709 1720 NULL,NULL, 0); 1710 if(!CHECK_INET_HANDLE( bInternet))1721 if(!CHECK_INET_HANDLE(hInternet)) 1711 1722 fprintf(stderr,"WARNING : hInternet handle failed to initialize"); 1712 1723 #ifdef POST_DEBUG 1713 1724 curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1); 1714 1725 #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, 1716 1728 INTERNET_FLAG_NO_CACHE_WRITE,0); 1729 processDownloads(&bInternet); 1717 1730 char* tmp= 1718 (char*)malloc(( res1.nDataLen+1)*sizeof(char));1731 (char*)malloc((bInternet.ihandle[0].nDataLen+1)*sizeof(char)); 1719 1732 if(tmp == NULL){ 1720 1733 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL); 1721 1734 } 1722 1735 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); 1727 1740 map *btmp=getMap(tmpmaps->content,"href"); 1728 1741 if(btmp!=NULL){ 1729 1742 #ifdef POST_DEBUG 1730 1743 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]), 1735 1748 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_DEBUG1748 fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);1749 #endif1750 1749 } 1750 free(tmp); 1751 1751 } 1752 1752 } 1753 1753 cur3=cur3->next; 1754 1754 } 1755 InternetCloseHandle(hInternetP);1756 1755 #ifdef POST_DEBUG 1757 1756 fprintf(stderr,"Header and Body was parsed from Reference \n"); … … 1901 1900 free(REQUEST); 1902 1901 free(SERVICE_URL); 1903 InternetCloseHandle( hInternet);1902 InternetCloseHandle(&hInternet); 1904 1903 freeService(&s1); 1905 1904 free(s1); … … 2148 2147 } 2149 2148 2149 runHttpRequests(&m,&request_input_real_format,&hInternet); 2150 2150 2151 2151 // if(CHECK_INET_HANDLE(hInternet)) 2152 InternetCloseHandle( hInternet);2152 InternetCloseHandle(&hInternet); 2153 2153 2154 2154 #ifdef DEBUG
Note: See TracChangeset
for help on using the changeset viewer.