mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 13:32:58 +03:00
tpws : better gzip checking. fixing missing fclose
This commit is contained in:
parent
f8dd9f3d23
commit
5dd7834314
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -77,5 +77,7 @@ zerr:
|
|||||||
bool is_gzip(FILE* F)
|
bool is_gzip(FILE* F)
|
||||||
{
|
{
|
||||||
unsigned char magic[2];
|
unsigned char magic[2];
|
||||||
return !fseek(F,0,SEEK_SET) && fread(magic, 1, 2, F)==2 && magic[0]==0x1F && magic[1]==0x8B;
|
bool b = !fseek(F,0,SEEK_SET) && fread(magic, 1, 2, F)==2 && magic[0]==0x1F && magic[1]==0x8B;
|
||||||
|
fseek(F,0,SEEK_SET);
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
@ -41,40 +41,37 @@ bool LoadHostList(strpool **hostlist, char *filename)
|
|||||||
fprintf(stderr, "Could not open %s\n", filename);
|
fprintf(stderr, "Could not open %s\n", filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((r=z_readfile(F,&zbuf,&zsize))==Z_OK)
|
|
||||||
{
|
|
||||||
|
|
||||||
printf("zlib compression detected. uncompressed size : %zu\n", zsize);
|
if (is_gzip(F))
|
||||||
|
{
|
||||||
|
r = z_readfile(F,&zbuf,&zsize);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
|
if (r==Z_OK)
|
||||||
p = zbuf;
|
|
||||||
e = zbuf + zsize;
|
|
||||||
while(p<e)
|
|
||||||
{
|
{
|
||||||
if (!addpool(hostlist,&p,e))
|
printf("zlib compression detected. uncompressed size : %zu\n", zsize);
|
||||||
|
|
||||||
|
p = zbuf;
|
||||||
|
e = zbuf + zsize;
|
||||||
|
while(p<e)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Not enough memory to store host list : %s\n", filename);
|
if (!addpool(hostlist,&p,e))
|
||||||
free(zbuf);
|
{
|
||||||
return false;
|
fprintf(stderr, "Not enough memory to store host list : %s\n", filename);
|
||||||
|
free(zbuf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ct++;
|
||||||
}
|
}
|
||||||
ct++;
|
free(zbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "zlib decompression failed : result %d\n",r);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
free(zbuf);
|
|
||||||
}
|
|
||||||
else if (r!=Z_DATA_ERROR)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "zlib decompression failed : result %d\n",r);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (is_gzip(F))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "hostlist is gzip but is broken : %s\n",filename);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(F,0,SEEK_SET);
|
|
||||||
printf("loading plain text list\n",r);
|
printf("loading plain text list\n",r);
|
||||||
|
|
||||||
while (fgets(s, 256, F))
|
while (fgets(s, 256, F))
|
||||||
@ -90,6 +87,7 @@ bool LoadHostList(strpool **hostlist, char *filename)
|
|||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Loaded %d hosts from %s\n", ct, filename);
|
printf("Loaded %d hosts from %s\n", ct, filename);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user