Changeset 490 for trunk/zoo-project/zoo-kernel/ulinet.c
- Timestamp:
- Jun 27, 2014, 1:14:39 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/ulinet.c
r478 r490 27 27 28 28 #define _ULINET 29 #define MAX_WAIT_MSECS 180*1000 /* Wait max. 180 seconds */ 29 30 #include "ulinet.h" 30 31 #include <assert.h> … … 162 163 #endif 163 164 164 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 165 165 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 166 166 HINTERNET ret; 167 struct MemoryStruct header; 167 ret.handle=curl_multi_init(); 168 ret.ihandle=NULL; 168 169 ret.hasCacheFile=0; 169 170 ret.nDataAlloc = 0; 170 171 ret.mimeType = NULL; 171 172 curl_global_init(CURL_GLOBAL_ALL|CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32); 173 ret.handle=curl_easy_init(); 174 175 curl_easy_setopt(ret.handle, CURLOPT_COOKIEFILE, "ALL"); 176 #ifndef TIGER 177 curl_easy_setopt(ret.handle, CURLOPT_COOKIELIST, "ALL"); 178 #endif 179 curl_easy_setopt(ret.handle, CURLOPT_USERAGENT, lpszAgent); 180 181 curl_easy_setopt(ret.handle,CURLOPT_FOLLOWLOCATION,1); 182 curl_easy_setopt(ret.handle,CURLOPT_MAXREDIRS,3); 183 184 header.memory=NULL; 185 header.size = 0; 186 187 curl_easy_setopt(ret.handle, CURLOPT_HEADERFUNCTION, header_write_data); 188 curl_easy_setopt(ret.handle, CURLOPT_WRITEHEADER, (void *)&header); 189 190 #ifdef MSG_LAF_VERBOSE 191 curl_easy_setopt(ret.handle, CURLOPT_VERBOSE, 1); 192 #endif 193 172 ret.agent=strdup(lpszAgent); 194 173 return ret; 195 174 } … … 206 185 handle.nDataAlloc = handle.nDataLen = 0; 207 186 } 187 if(handle.ihandle!=NULL) 188 curl_easy_cleanup(handle.ihandle); 208 189 if(handle.handle) 209 curl_ easy_cleanup(handle.handle);210 curl_global_cleanup();190 curl_multi_cleanup(handle.handle); 191 free(handle.agent); 211 192 } 212 193 … … 214 195 215 196 char filename[255]; 197 struct MemoryStruct header; 198 216 199 hInternet.nDataLen = 0; 217 200 218 201 hInternet.nDataAlloc = 0; 219 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"); 208 #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); 215 216 header.memory=NULL; 217 header.size = 0; 218 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); 224 #endif 225 220 226 221 227 switch(dwFlags) … … 223 229 case INTERNET_FLAG_NO_CACHE_WRITE: 224 230 hInternet.hasCacheFile=-1; 225 curl_easy_setopt(hInternet. handle, CURLOPT_WRITEFUNCTION, write_data_into);226 curl_easy_setopt(hInternet. handle, CURLOPT_WRITEDATA, &hInternet);231 curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEFUNCTION, write_data_into); 232 curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEDATA, &hInternet); 227 233 break; 228 234 default: … … 236 242 237 243 hInternet.hasCacheFile=1; 238 curl_easy_setopt(hInternet. handle, CURLOPT_WRITEFUNCTION, NULL);239 curl_easy_setopt(hInternet. handle, CURLOPT_WRITEDATA, hInternet.file);244 curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEFUNCTION, NULL); 245 curl_easy_setopt(hInternet.ihandle, CURLOPT_WRITEDATA, hInternet.file); 240 246 hInternet.nDataLen=0; 241 247 break; … … 250 256 #endif 251 257 //curl_easy_setopt(hInternet.handle,CURLOPT_COOKIE,lpszHeaders); 252 curl_easy_setopt(hInternet. handle,CURLOPT_POST,1);258 curl_easy_setopt(hInternet.ihandle,CURLOPT_POST,1); 253 259 #ifdef ULINET_DEBUG 254 260 fprintf(stderr,"** (%s) %d **\n",lpszHeaders,dwHeadersLength); 255 curl_easy_setopt(hInternet. handle,CURLOPT_VERBOSE,1);256 #endif 257 curl_easy_setopt(hInternet. handle,CURLOPT_POSTFIELDS,lpszHeaders);261 curl_easy_setopt(hInternet.ihandle,CURLOPT_VERBOSE,1); 262 #endif 263 curl_easy_setopt(hInternet.ihandle,CURLOPT_POSTFIELDS,lpszHeaders); 258 264 //curl_easy_setopt(hInternet.handle,CURLOPT_POSTFIELDSIZE,dwHeadersLength+1); 259 265 if(hInternet.header!=NULL) 260 curl_easy_setopt(hInternet.handle,CURLOPT_HTTPHEADER,hInternet.header); 261 } 262 263 curl_easy_setopt(hInternet.handle,CURLOPT_URL,lpszUrl); 264 curl_easy_perform(hInternet.handle); 265 curl_easy_getinfo(hInternet.handle,CURLINFO_CONTENT_TYPE,&hInternet.mimeType); 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); 291 266 292 #ifdef ULINET_DEBUG 267 293 fprintf(stderr,"DEBUG MIMETYPE: %s\n",hInternet.mimeType); … … 274 300 memset(&CCookie[0],0,1024); 275 301 #ifndef TIGER 276 curl_easy_setopt(hInternet. handle, CURLOPT_COOKIELIST, "ALL");302 curl_easy_setopt(hInternet.ihandle, CURLOPT_COOKIELIST, "ALL"); 277 303 #endif 278 304 return 1;
Note: See TracChangeset
for help on using the changeset viewer.