Ejemplo n.º 1
0
void Probe(int Threshold)
{
	static const char *Servers[] = {
		"8.8.8.8",
		"208.67.220.220",
		"199.85.126.10",
		"4.2.2.1",
		"8.26.56.26",
	};

	static const char *Domains[] = {
		"www.youtube.com",
		"www.googlevideo.com",
		"twitter.com",
		"www.facebook.com"
	};

	int	Pass = 0;

	StringList	l;

	StringChunk	s;

	StringList_Init(&l, NULL, ',');
	StringChunk_Init(&s, NULL);

	while( Threshold > 0 )
	{
		printf("; Pass %d:\n", Pass + 1);

		if( ProbeFakeAddresses(Servers[Pass % (sizeof(Servers) / sizeof(const char *))], Domains[Pass % (sizeof(Domains) / sizeof(const char *))], &l) > 0 )
		{
			const char *Itr = NULL;
			int NumberOfNew = 0;

			Itr = StringList_GetNext(&l, NULL);

			while( Itr != NULL )
			{
				if( StringChunk_Match_NoWildCard(&s, Itr, NULL, NULL) == FALSE )
				{
					StringChunk_Add(&s, Itr, NULL, 0);
					printf("%s\n", Itr);
					++NumberOfNew;
				}

				Itr = StringList_GetNext(&l, Itr);
			}

			if( NumberOfNew == 0 )
			{
				--Threshold;
			} else {
				Threshold += 2;
			}
		} else {
			--Threshold;
		}

		StringList_Clear(&l);

		++Pass;
	}

	StringList_Free(&l);
	StringChunk_Free(&s, TRUE);
}
Ejemplo n.º 2
0
static int LoadGfwListFile(const char *File, BOOL NeedBase64Decode)
{
	FILE	*fp;
	ReadLineStatus Status;
	char	Buffer[256];
	int		Count = 0;

	GFWListContainer *Container;

	if( (NeedBase64Decode == TRUE) && (Base64Decode(File) != 0) )
	{
		return -1;
	}

	fp = fopen(File, "r");
	if( fp == NULL )
	{
		return -2;
	}

	Container = SafeMalloc(sizeof(GFWListContainer));
	if( Container == NULL )
	{
		return -3;
	}

	if( StringChunk_Init(&(Container -> GFWList), NULL) != 0 )
	{
		return -4;
	}

	while(TRUE)
	{
		Status = ReadLine(fp, Buffer, sizeof(Buffer));

		switch(Status)
		{
			case READ_FAILED_OR_END:
				goto DONE;
				break;

			case READ_DONE:
				if( ParseGfwListItem(Buffer, Container) == TRUE )
				{
					++Count;
				}

				break;

			case READ_TRUNCATED:
				INFO("GFWList Item is too long : %s\n", Buffer);
				ReadLine_GoToNextLine(fp);
				break;
		}
	}

DONE:
	fclose(fp);

	if( Count == 0 )
	{
		StringChunk_Free((StringChunk *)&(Container -> GFWList), TRUE);
		SafeFree(Container);
		return -4;
	}

	/* Evict old container */
	RWLock_WrLock(GFWListLock);

	if( MainContainer != NULL )
	{
		StringChunk_Free((StringChunk *)&(MainContainer -> GFWList), TRUE);
		SafeFree((void *)MainContainer);
	}

	MainContainer = Container;

	RWLock_UnWLock(GFWListLock);

	return Count;
}