Changeset 492 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Jul 11, 2014, 10:14:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.