Changeset 550 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Feb 3, 2015, 12:59:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r542 r550 2432 2432 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2433 2433 if(tmp!=NULL){ 2434 xmlNodeSetContent(nc1, BAD_CAST tmp->value); 2434 xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value); 2435 xmlAddChild(nc1,txt); 2435 2436 } 2436 2437 else{ … … 2442 2443 } 2443 2444 2445 /************************************************************************/ 2446 /* readGeneratedFile() */ 2447 /************************************************************************/ 2448 2449 /** 2450 * Read a file generated by a service. 2451 * 2452 * @param m the conf maps 2453 * @param content the output item 2454 * @param filename the file to read 2455 */ 2456 void readGeneratedFile(maps* m,map* content,char* filename){ 2457 FILE * file=fopen(filename,"rb"); 2458 fseek(file, 0, SEEK_END); 2459 long count = ftell(file); 2460 rewind(file); 2461 struct stat file_status; 2462 stat(filename, &file_status); 2463 if(file==NULL){ 2464 fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename); 2465 setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later"); 2466 return ; 2467 } 2468 map* tmpMap1=getMap(content,"value"); 2469 if(tmpMap1==NULL){ 2470 addToMap(content,"value",""); 2471 tmpMap1=getMap(content,"value"); 2472 } 2473 free(tmpMap1->value); 2474 tmpMap1->value=(char*) malloc((count+1)*sizeof(char)); 2475 fread(tmpMap1->value,1,count*sizeof(char),file); 2476 fclose(file); 2477 char rsize[100]; 2478 sprintf(rsize,"%d",count*sizeof(char)); 2479 addToMap(tmpMap1,"size",rsize); 2480 } 2444 2481 2445 2482 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, … … 2503 2540 } 2504 2541 2542 if(res==SERVICE_FAILED){ 2543 map * errormap; 2544 map *lenv; 2545 lenv=getMapFromMaps(m,"lenv","message"); 2546 char *tmp0; 2547 if(lenv!=NULL){ 2548 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2549 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2550 } 2551 else{ 2552 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2553 sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service.")); 2554 } 2555 errormap = createMap("text",tmp0); 2556 free(tmp0); 2557 addToMap(errormap,"code", "InternalError"); 2558 dumpMap(errormap); 2559 printExceptionReportResponse(m,errormap); 2560 freeMap(&errormap); 2561 free(errormap); 2562 return; 2563 } 2564 2505 2565 2506 2566 if(asRaw==0){ … … 2521 2581 #endif 2522 2582 { 2523 elements* in=getElements(s->outputs,tmpI->name); 2524 char *format=NULL; 2525 if(in!=NULL){ 2526 format=strdup(in->format); 2527 }else 2528 format=strdup("LiteralData"); 2529 if(strcasecmp(format,"BoundingBoxData")==0){ 2530 addToMap(tmpI->content,"extension","xml"); 2531 addToMap(tmpI->content,"mimeType","text/xml"); 2532 addToMap(tmpI->content,"encoding","UTF-8"); 2533 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2534 } 2535 map *ext=getMap(tmpI->content,"extension"); 2536 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2537 char *file_name,*file_path; 2538 bool hasExt=true; 2539 if(ext==NULL){ 2540 // We can fallback to a default list of supported formats using 2541 // mimeType information if present here. Maybe we can add more formats 2542 // here. 2543 // If mimeType was not found, we then set txt as the default extension 2544 map* mtype=getMap(tmpI->content,"mimeType"); 2545 if(mtype!=NULL){ 2546 if(strcasecmp(mtype->value,"text/xml")==0) 2547 ext=createMap("extension","xml"); 2548 else if(strcasecmp(mtype->value,"application/json")==0) 2549 ext=createMap("extension","js"); 2550 else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0) 2551 ext=createMap("extension","kml"); 2552 else if(strncmp(mtype->value,"image/",6)==0) 2553 ext=createMap("extension",strstr(mtype->value,"/")+1); 2554 else 2555 ext=createMap("extension","txt"); 2583 elements* in=getElements(s->outputs,tmpI->name); 2584 char *format=NULL; 2585 if(in!=NULL){ 2586 format=strdup(in->format); 2587 }else 2588 format=strdup("LiteralData"); 2589 if(strcasecmp(format,"BoundingBoxData")==0){ 2590 addToMap(tmpI->content,"extension","xml"); 2591 addToMap(tmpI->content,"mimeType","text/xml"); 2592 addToMap(tmpI->content,"encoding","UTF-8"); 2593 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2556 2594 } 2557 else 2558 ext=createMap("extension","txt"); 2559 hasExt=false; 2560 } 2561 file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char)); 2562 int cpid0=cpid+time(NULL); 2563 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value); 2564 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2565 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2566 FILE *ofile=fopen(file_path,"wb"); 2567 if(ofile==NULL){ 2568 char tmpMsg[1024]; 2569 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name); 2570 map * errormap = createMap("text",tmpMsg); 2571 addToMap(errormap,"code", "InternalError"); 2572 printExceptionReportResponse(m,errormap); 2573 freeMap(&errormap); 2574 free(errormap); 2595 2596 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2597 2598 map *gfile=getMap(tmpI->content,"generated_file"); 2599 char *file_name; 2600 if(gfile!=NULL){ 2601 readGeneratedFile(m,tmpI->content,gfile->value); 2602 file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char)); 2603 for(int i=0;i<strlen(gfile->value);i++) 2604 file_name[i]=gfile->value[i+strlen(tmp1->value)]; 2605 } 2606 else{ 2607 map *ext=getMap(tmpI->content,"extension"); 2608 char *file_path; 2609 bool hasExt=true; 2610 if(ext==NULL){ 2611 // We can fallback to a default list of supported formats using 2612 // mimeType information if present here. Maybe we can add more formats 2613 // here. 2614 // If mimeType was not found, we then set txt as the default extension 2615 map* mtype=getMap(tmpI->content,"mimeType"); 2616 if(mtype!=NULL) { 2617 if(strncasecmp(mtype->value,"text/xml",8)==0) 2618 ext=createMap("extension","xml"); 2619 else if(strncasecmp(mtype->value,"application/zip",15)==0) 2620 ext=createMap("extension","zip"); 2621 else if(strncasecmp(mtype->value,"application/json",16)==0) 2622 ext=createMap("extension","js"); 2623 else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0) 2624 ext=createMap("extension","kml"); 2625 else if(strncmp(mtype->value,"image/",6)==0) 2626 ext=createMap("extension",strstr(mtype->value,"/")+1); 2627 else 2628 ext=createMap("extension","txt"); 2629 } 2630 else 2631 ext=createMap("extension","txt"); 2632 hasExt=false; 2633 } 2634 file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char)); 2635 int cpid0=cpid+time(NULL); 2636 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value); 2637 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2638 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2639 FILE *ofile=fopen(file_path,"wb"); 2640 if(ofile==NULL){ 2641 char tmpMsg[1024]; 2642 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name); 2643 map * errormap = createMap("text",tmpMsg); 2644 addToMap(errormap,"code", "InternalError"); 2645 printExceptionReportResponse(m,errormap); 2646 freeMap(&errormap); 2647 free(errormap); 2648 free(file_name); 2649 free(file_path); 2650 return; 2651 } 2652 free(file_path); 2653 if(!hasExt){ 2654 freeMap(&ext); 2655 free(ext); 2656 } 2657 toto=getMap(tmpI->content,"value"); 2658 if(strcasecmp(format,"BoundingBoxData")!=0){ 2659 map* size=getMap(tmpI->content,"size"); 2660 if(size!=NULL && toto!=NULL) 2661 fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile); 2662 else 2663 if(toto!=NULL && toto->value!=NULL) 2664 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2665 }else{ 2666 printBoundingBoxDocument(m,tmpI,ofile); 2667 } 2668 fclose(ofile); 2669 2670 } 2671 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2672 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2673 char *file_url; 2674 if(strncasecmp(tmp2->value,"http://",7)==0 || 2675 strncasecmp(tmp2->value,"https://",8)==0){ 2676 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2677 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2678 }else{ 2679 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2680 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2681 } 2682 addToMap(tmpI->content,"Reference",file_url); 2683 free(format); 2575 2684 free(file_name); 2576 free(file_path); 2577 return; 2578 } 2579 free(file_path); 2580 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2581 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2582 char *file_url; 2583 if(strncasecmp(tmp2->value,"http://",7)==0 || 2584 strncasecmp(tmp2->value,"https://",8)==0){ 2585 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2586 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2587 }else{ 2588 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2589 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2590 } 2591 addToMap(tmpI->content,"Reference",file_url); 2592 if(!hasExt){ 2593 freeMap(&ext); 2594 free(ext); 2595 } 2596 toto=getMap(tmpI->content,"value"); 2597 if(strcasecmp(format,"BoundingBoxData")!=0){ 2598 map* size=getMap(tmpI->content,"size"); 2599 if(size!=NULL && toto!=NULL) 2600 fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile); 2601 else 2602 if(toto!=NULL && toto->value!=NULL) 2603 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2604 }else{ 2605 printBoundingBoxDocument(m,tmpI,ofile); 2606 } 2607 free(format); 2608 fclose(ofile); 2609 free(file_name); 2610 free(file_url); 2685 free(file_url); 2686 2611 2687 } 2612 2688 #ifdef USE_MS … … 2628 2704 request_inputs, 2629 2705 request_outputs); 2630 } 2631 else{ 2632 if(res==SERVICE_FAILED){ 2633 map * errormap; 2634 map *lenv; 2635 lenv=getMapFromMaps(m,"lenv","message"); 2636 char *tmp0; 2637 if(lenv!=NULL){ 2638 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2639 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2640 } 2641 else{ 2642 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2643 sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service.")); 2644 } 2645 errormap = createMap("text",tmp0); 2646 free(tmp0); 2647 addToMap(errormap,"code", "InternalError"); 2706 } 2707 else{ 2708 /** 2709 * We get the requested output or fallback to the first one if the 2710 * requested one is not present in the resulting outputs maps. 2711 */ 2712 maps* tmpI=NULL; 2713 map* tmpIV=getMap(request_inputs1,"RawDataOutput"); 2714 if(tmpIV!=NULL){ 2715 tmpI=getMaps(request_outputs,tmpIV->value); 2716 } 2717 if(tmpI==NULL) 2718 tmpI=request_outputs; 2719 elements* e=getElements(s->outputs,tmpI->name); 2720 if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ 2721 printBoundingBoxDocument(m,tmpI,NULL); 2722 }else{ 2723 map *gfile=getMap(tmpI->content,"generated_file"); 2724 if(gfile!=NULL){ 2725 readGeneratedFile(m,tmpI->content,gfile->value); 2726 } 2727 toto=getMap(tmpI->content,"value"); 2728 if(toto==NULL){ 2729 char tmpMsg[1024]; 2730 sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name); 2731 map * errormap = createMap("text",tmpMsg); 2732 addToMap(errormap,"code", "InvalidParameterValue"); 2648 2733 printExceptionReportResponse(m,errormap); 2649 2734 freeMap(&errormap); … … 2651 2736 return; 2652 2737 } 2653 /** 2654 * We get the requested output or fallback to the first one if the 2655 * requested one is not present in the resulting outputs maps. 2656 */ 2657 maps* tmpI=NULL; 2658 map* tmpIV=getMap(request_inputs1,"RawDataOutput"); 2659 if(tmpIV!=NULL){ 2660 tmpI=getMaps(request_outputs,tmpIV->value); 2661 } 2662 if(tmpI==NULL) 2663 tmpI=request_outputs; 2664 elements* e=getElements(s->outputs,tmpI->name); 2665 if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ 2666 printBoundingBoxDocument(m,tmpI,NULL); 2667 }else{ 2668 toto=getMap(tmpI->content,"value"); 2669 if(toto==NULL){ 2670 char tmpMsg[1024]; 2671 sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name); 2672 map * errormap = createMap("text",tmpMsg); 2673 addToMap(errormap,"code", "InvalidParameterValue"); 2674 printExceptionReportResponse(m,errormap); 2675 freeMap(&errormap); 2676 free(errormap); 2677 return; 2678 } 2679 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2680 if(fname!=NULL) 2681 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2682 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2683 if(rs!=NULL) 2684 printf("Content-Length: %s\r\n",rs->value); 2685 printHeaders(m); 2686 char mime[1024]; 2687 map* mi=getMap(tmpI->content,"mimeType"); 2688 #ifdef DEBUG 2689 fprintf(stderr,"SERVICE OUTPUTS\n"); 2690 dumpMaps(request_outputs); 2691 fprintf(stderr,"SERVICE OUTPUTS\n"); 2692 #endif 2693 map* en=getMap(tmpI->content,"encoding"); 2694 if(mi!=NULL && en!=NULL) 2738 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2739 if(fname!=NULL) 2740 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2741 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2742 if(rs!=NULL) 2743 printf("Content-Length: %s\r\n",rs->value); 2744 printHeaders(m); 2745 char mime[1024]; 2746 map* mi=getMap(tmpI->content,"mimeType"); 2747 #ifdef DEBUG 2748 fprintf(stderr,"SERVICE OUTPUTS\n"); 2749 dumpMaps(request_outputs); 2750 fprintf(stderr,"SERVICE OUTPUTS\n"); 2751 #endif 2752 map* en=getMap(tmpI->content,"encoding"); 2753 if(mi!=NULL && en!=NULL) 2754 sprintf(mime, 2755 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 2756 mi->value,en->value); 2757 else 2758 if(mi!=NULL) 2695 2759 sprintf(mime, 2696 "Content-Type: %s; charset= %s\r\nStatus: 200 OK\r\n\r\n",2697 mi->value ,en->value);2760 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2761 mi->value); 2698 2762 else 2699 if(mi!=NULL) 2700 sprintf(mime, 2701 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2702 mi->value); 2703 else 2704 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2705 printf("%s",mime); 2706 if(rs!=NULL) 2707 fwrite(toto->value,1,atoi(rs->value),stdout); 2708 else 2709 fwrite(toto->value,1,strlen(toto->value),stdout); 2710 #ifdef DEBUG 2711 dumpMap(toto); 2712 #endif 2713 } 2714 } 2763 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2764 printf("%s",mime); 2765 if(rs!=NULL) 2766 fwrite(toto->value,1,atoi(rs->value),stdout); 2767 else 2768 fwrite(toto->value,1,strlen(toto->value),stdout); 2769 #ifdef DEBUG 2770 dumpMap(toto); 2771 #endif 2772 } 2773 } 2715 2774 } 2716 2775 … … 3220 3279 int index=0; 3221 3280 while(content!=NULL){ 3222 if((tmp1=getMap(content->content,"href")) || 3223 (tmp1=getMap(content->content,"xlink:href"))){ 3224 if(getMap(content->content,"isCached")==NULL){ 3225 char* fcontent; 3226 char *mimeType=NULL; 3227 int fsize=0; 3228 3229 fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char)); 3230 if(fcontent == NULL){ 3231 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 3281 3282 map* length=getMap(content->content,"length"); 3283 int shouldClean=-1; 3284 if(length==NULL){ 3285 length=createMap("length","1"); 3286 shouldClean=1; 3287 } 3288 for(int i=0;i<atoi(length->value);i++){ 3289 3290 char* fcontent; 3291 char *mimeType=NULL; 3292 int fsize=0; 3293 char cname[15]; 3294 char vname[11]; 3295 char vname1[11]; 3296 char sname[9]; 3297 char icname[14]; 3298 char xname[16]; 3299 if(index>0) 3300 sprintf(vname1,"value_%d",index); 3301 else 3302 sprintf(vname1,"value"); 3303 3304 if(i>0){ 3305 tmp1=getMap(content->content,cname); 3306 sprintf(cname,"cache_file_%d",i); 3307 sprintf(vname,"value_%d",i); 3308 sprintf(sname,"size_%d",i); 3309 sprintf(icname,"isCached_%d",i); 3310 sprintf(xname,"Reference_%d",i); 3311 }else{ 3312 sprintf(cname,"cache_file"); 3313 sprintf(vname,"value"); 3314 sprintf(icname,"isCached"); 3315 sprintf(sname,"size"); 3316 sprintf(xname,"Reference"); 3317 } 3318 3319 map* tmap=getMapFromMaps(*m,"orequests",vname1); 3320 if((tmp1=getMap(content->content,xname))!=NULL && strcasecmp(tmap->value,tmp1->value)==0 ){ 3321 if(getMap(content->content,icname)==NULL){ 3322 3323 fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char)); 3324 if(fcontent == NULL){ 3325 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 3326 } 3327 size_t dwRead; 3328 InternetReadFile(hInternet->ihandle[index], 3329 (LPVOID)fcontent, 3330 hInternet->ihandle[index].nDataLen, 3331 &dwRead); 3332 fcontent[hInternet->ihandle[index].nDataLen]=0; 3333 fsize=hInternet->ihandle[index].nDataLen; 3334 if(hInternet->ihandle[index].mimeType==NULL) 3335 mimeType=strdup("none"); 3336 else 3337 mimeType=strdup((char*)hInternet->ihandle[index].mimeType); 3338 3339 map* tmpMap=getMapOrFill(&content->content,vname,""); 3340 free(tmpMap->value); 3341 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 3342 if(tmpMap->value==NULL){ 3343 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 3344 } 3345 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 3346 3347 char ltmp1[256]; 3348 sprintf(ltmp1,"%d",fsize); 3349 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 3350 if(tmp!=NULL){ 3351 char* md5str=getMd5(tmp1->value); 3352 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 3353 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 3354 addToMap(content->content,cname,fname); 3355 free(fname); 3356 } 3357 addToMap(content->content,sname,ltmp1); 3358 addToCache(*m,tmp1->value,fcontent,mimeType,fsize); 3359 free(fcontent); 3360 free(mimeType); 3361 dumpMaps(content); 3362 index++; 3363 3232 3364 } 3233 size_t dwRead;3234 InternetReadFile(hInternet->ihandle[index],3235 (LPVOID)fcontent,3236 hInternet->ihandle[index].nDataLen,3237 &dwRead);3238 fcontent[hInternet->ihandle[index].nDataLen]=0;3239 fsize=hInternet->ihandle[index].nDataLen;3240 if(hInternet->ihandle[index].mimeType==NULL)3241 mimeType=strdup("none");3242 else3243 mimeType=strdup((char*)hInternet->ihandle[index].mimeType);3244 3245 map* tmpMap=getMapOrFill(&content->content,"value","");3246 free(tmpMap->value);3247 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));3248 if(tmpMap->value==NULL){3249 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);3250 }3251 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));3252 3253 char ltmp1[256];3254 sprintf(ltmp1,"%d",fsize);3255 addToMap(content->content,"size",ltmp1);3256 addToCache(*m,tmp1->value,fcontent,mimeType,fsize);3257 free(fcontent);3258 free(mimeType);3259 3365 } 3260 index++; 3261 } 3366 } 3367 if(shouldClean>0){ 3368 freeMap(&length); 3369 free(length); 3370 } 3371 3262 3372 content=content->next; 3263 3373 } 3374 3264 3375 } 3265 3376 } … … 3274 3385 char *mimeType=NULL; 3275 3386 int fsize=0; 3387 3388 map* t=getMap(*content,"xlink:href"); 3389 if(t==NULL){ 3390 t=getMap((*content),"href"); 3391 addToMap(*content,"xlink:href",url); 3392 } 3393 3276 3394 if(cached!=NULL){ 3395 3277 3396 struct stat f_status; 3278 3397 int s=stat(cached, &f_status); … … 3284 3403 fcontent[fsize]=0; 3285 3404 fclose(f); 3405 addToMap(*content,"cache_file",cached); 3286 3406 } 3287 3407 cached[strlen(cached)-1]='m'; … … 3294 3414 fclose(f); 3295 3415 } 3416 3296 3417 }else{ 3297 3418 hInternet->waitingRequests[hInternet->nb]=strdup(url); 3298 3419 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); 3420 maps *oreq=getMaps(*m,"orequests"); 3421 if(oreq==NULL){ 3422 oreq=(maps*)malloc(MAPS_SIZE); 3423 oreq->name=zStrdup("orequests"); 3424 oreq->content=createMap("value",url); 3425 oreq->next=NULL; 3426 addMapsToMaps(m,oreq); 3427 freeMaps(&oreq); 3428 free(oreq); 3429 }else{ 3430 setMapArray(oreq->content,"value",hInternet->nb-1,url); 3431 } 3299 3432 return 0; 3300 3433 } … … 3309 3442 3310 3443 free(tmpMap->value); 3444 3311 3445 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 3312 3446 if(tmpMap->value==NULL) 3313 3447 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 3314 3448 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 3315 3449 3316 3450 char ltmp1[256]; 3317 3451 sprintf(ltmp1,"%d",fsize); 3318 3452 addToMap(*content,"size",ltmp1); 3319 if(cached==NULL) 3453 if(cached==NULL){ 3320 3454 addToCache(*m,url,fcontent,mimeType,fsize); 3321 else 3455 } 3456 else{ 3322 3457 addToMap(*content,"isCached","true"); 3458 3459 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 3460 if(tmp!=NULL){ 3461 map *c=getMap((*content),"xlink:href"); 3462 char* md5str=getMd5(c->value); 3463 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 3464 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 3465 addToMap(*content,"cache_file",fname); 3466 free(fname); 3467 } 3468 } 3323 3469 free(fcontent); 3324 3470 free(mimeType);
Note: See TracChangeset
for help on using the changeset viewer.