Changeset 854 for branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
- Timestamp:
- Nov 21, 2017, 10:24:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
r851 r854 211 211 ret.agent=strdup(lpszAgent); 212 212 ret.nb=0; 213 ret.waitingRequests[ret.nb] = NULL; 213 214 ret.ihandle[ret.nb].header=NULL; 215 ret.ihandle[ret.nb].handle=NULL; 216 ret.ihandle[ret.nb].hasCacheFile=0; 217 ret.ihandle[ret.nb].nDataAlloc = 0; 218 ret.ihandle[ret.nb].url = NULL; 219 ret.ihandle[ret.nb].mimeType = NULL; 220 ret.ihandle[ret.nb].cookie = NULL; 221 ret.ihandle[ret.nb].nDataLen = 0; 222 ret.ihandle[ret.nb].nDataAlloc = 0; 223 ret.ihandle[ret.nb].pabyData = NULL; 224 ret.ihandle[ret.nb].post = NULL; 214 225 return ret; 226 } 227 228 /** 229 * Verify if the URL should use a shared cache or not. 230 * 231 * In case the security section contains a key named "shared", then if the 232 * domain listed in the shared key are contained in the url given as parameter 233 * then it return "SHARED" in other cases, it returns "OTHER". 234 * 235 * @param conf the main configuration file maps 236 * @param url the URL to evaluate 237 * @return a string "SHARED" in case the host is in a domain listed in the 238 * shared key, "OTHER" in other cases. 239 */ 240 char* getProvenance(maps* conf,const char* url){ 241 map* sharedCache=getMapFromMaps(conf,"security","shared"); 242 if(sharedCache!=NULL){ 243 char *res=NULL; 244 char *hosts=sharedCache->value; 245 char *curs=strtok(hosts,","); 246 while(curs!=NULL){ 247 fprintf(stderr,"### %s %d %s \n",__FILE__,__LINE__,strstr(url,curs)); 248 fflush(stderr); 249 if(strstr(url,curs)==NULL) 250 res="OTHER"; 251 else{ 252 res="SHARED"; 253 fprintf(stderr,"### %s %d %s \n",__FILE__,__LINE__,"SHARED"); 254 fflush(stderr); 255 return res; 256 } 257 curs=strtok(NULL,","); 258 } 259 return res; 260 } 261 return "OTHER"; 215 262 } 216 263 … … 282 329 int i; 283 330 for(i=0;i<handle->nb;i++){ 284 if( targetHosts->value[0]=='*'|| isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){331 if(strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){ 285 332 while (token != NULL){ 286 333 int length=strlen(token)+6; … … 297 344 } 298 345 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmp1); 299 if(strncmp(tmp1,"HTTP_COOKIE",11)!=0){ 300 tmpMap = getMapFromMaps(conf,"renv",tmp1); 301 if(tmpMap!=NULL) 302 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 346 //dumpMaps(conf); 347 tmpMap = getMapFromMaps(conf,"renv",tmp1); 348 if(tmpMap!=NULL){ 349 fprintf(stderr,"add header %s %s\n",token,tmpMap->value); 350 fflush(stderr); 351 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 303 352 } 304 353 free(tmp1); … … 321 370 void InternetCloseHandle(HINTERNET* handle0){ 322 371 int i=0; 323 for(i=0;i<handle0->nb;i++){ 324 _HINTERNET handle=handle0->ihandle[i]; 325 if(handle.hasCacheFile>0){ 326 fclose(handle.file); 327 unlink(handle.filename); 328 } 329 else{ 330 handle.pabyData = NULL; 331 handle.nDataAlloc = handle.nDataLen = 0; 332 } 333 if(handle0->ihandle[i].header!=NULL){ 334 curl_slist_free_all(handle0->ihandle[i].header); 335 handle0->ihandle[i].header=NULL; 336 } 337 if(handle.post!=NULL) 338 free(handle.post); 339 if(handle.url!=NULL) 340 free(handle.url); 341 if(handle.mimeType!=NULL) 342 free(handle.mimeType); 343 if(handle.cookie!=NULL) 344 free(handle.cookie); 345 } 346 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 347 fflush(stderr); 348 if(handle0->handle) 349 curl_multi_cleanup(handle0->handle); 350 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 351 fflush(stderr); 352 free(handle0->agent); 353 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 354 fflush(stderr); 355 for(i=handle0->nb-1;i>=0;i--){ 356 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 357 fflush(stderr); 358 free(handle0->waitingRequests[i]); 359 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 360 fflush(stderr); 372 if(handle0!=NULL){ 373 for(i=0;i<handle0->nb;i++){ 374 _HINTERNET handle=handle0->ihandle[i]; 375 if(handle.hasCacheFile>0){ 376 fclose(handle.file); 377 unlink(handle.filename); 378 } 379 else{ 380 handle.pabyData = NULL; 381 handle.nDataAlloc = handle.nDataLen = 0; 382 } 383 if(handle.header!=NULL){ 384 curl_slist_free_all(handle.header); 385 handle.header=NULL; 386 } 387 if(handle.post!=NULL){ 388 free(handle.post); 389 handle.post=NULL; 390 } 391 if(handle.url!=NULL){ 392 free(handle.url); 393 handle.url=NULL; 394 } 395 if(handle.mimeType!=NULL){ 396 free(handle.mimeType); 397 handle.mimeType=NULL; 398 } 399 if(handle.cookie!=NULL){ 400 free(handle.cookie); 401 handle.cookie=NULL; 402 } 403 if(handle0->waitingRequests[i]!=NULL){ 404 free(handle0->waitingRequests[i]); 405 handle0->waitingRequests[i]=NULL; 406 } 407 } 408 if(handle0->handle) 409 curl_multi_cleanup(handle0->handle); 410 if(handle0->agent!=NULL){ 411 free(handle0->agent); 412 handle0->agent=NULL; 413 } 361 414 } 362 415 } … … 377 430 struct MemoryStruct header; 378 431 432 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 433 fflush(stderr); 379 434 hInternet->ihandle[hInternet->nb].handle=curl_easy_init( ); 435 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 436 fflush(stderr); 380 437 hInternet->ihandle[hInternet->nb].hasCacheFile=0; 438 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 439 fflush(stderr); 381 440 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 441 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 442 fflush(stderr); 382 443 hInternet->ihandle[hInternet->nb].url = NULL; 444 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 445 fflush(stderr); 383 446 hInternet->ihandle[hInternet->nb].mimeType = NULL; 447 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 448 fflush(stderr); 384 449 hInternet->ihandle[hInternet->nb].cookie = NULL; 450 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 451 fflush(stderr); 385 452 hInternet->ihandle[hInternet->nb].nDataLen = 0; 453 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 454 fflush(stderr); 386 455 hInternet->ihandle[hInternet->nb].id = hInternet->nb; 456 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 457 fflush(stderr); 387 458 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 459 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 460 fflush(stderr); 388 461 hInternet->ihandle[hInternet->nb].pabyData = NULL; 462 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 463 fflush(stderr); 389 464 hInternet->ihandle[hInternet->nb].post = NULL; 465 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 466 fflush(stderr); 390 467 391 468 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL"); 469 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 470 fflush(stderr); 392 471 #ifndef TIGER 393 472 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIELIST, "ALL"); 394 473 #endif 395 474 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_USERAGENT, hInternet->agent); 475 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 476 fflush(stderr); 396 477 397 478 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_FOLLOWLOCATION,1); 479 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 480 fflush(stderr); 398 481 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_MAXREDIRS,3); 482 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 483 fflush(stderr); 399 484 400 485 header.memory=NULL; … … 402 487 403 488 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_HEADERFUNCTION, header_write_data); 489 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 490 fflush(stderr); 404 491 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEHEADER, (void *)&header); 492 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 493 fflush(stderr); 405 494 406 495 #ifdef MSG_LAF_VERBOSE … … 431 520 break; 432 521 } 522 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 523 fflush(stderr); 433 524 #ifdef ULINET_DEBUG 434 525 fprintf(stderr,"URL (%s)\nBODY (%s)\n",lpszUrl,lpszHeaders); … … 448 539 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength); 449 540 } 541 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 542 fflush(stderr); 450 543 if(hInternet->ihandle[hInternet->nb].header!=NULL) 451 544 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_HTTPHEADER,hInternet->ihandle[hInternet->nb].header); 452 545 546 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 547 fflush(stderr); 453 548 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl); 454 549 hInternet->ihandle[hInternet->nb].url = zStrdup(lpszUrl); 550 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 551 fflush(stderr); 455 552 456 553 curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle); 554 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 555 fflush(stderr); 457 556 458 557 hInternet->ihandle[hInternet->nb].header=NULL; 558 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 559 fflush(stderr); 459 560 ++hInternet->nb; 561 hInternet->ihandle[hInternet->nb].header=NULL; 460 562 461 563 #ifdef ULINET_DEBUG … … 481 583 for(i=0;i<hInternet->nb;i++){ 482 584 char *tmp; 585 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 483 586 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp); 587 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 484 588 if(tmp!=NULL) 485 589 hInternet->ihandle[i].mimeType=strdup(tmp); 590 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 486 591 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code); 592 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 487 593 curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle); 594 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 488 595 curl_easy_cleanup(hInternet->ihandle[i].handle); 596 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 489 597 //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].mimeType); 490 598 //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].pabyData);
Note: See TracChangeset
for help on using the changeset viewer.