void StringChunk_Free(StringChunk *dl) { StringList_Free(&(dl -> List)); HashTable_Free(&(dl -> List_Pos)); StringList_Free(&(dl -> List_W)); Array_Free(&(dl -> List_W_Pos)); ExtendableBuffer_Free(&(dl -> AdditionalDataChunk)); }
static int LoadDedicatedServer(void) { const StringList *DedicatedServer = ConfigGetStringList(&ConfigInfo, "DedicatedServer"); const char *Itr = NULL; char Domain[256]; char Server[64]; Itr = StringList_GetNext(DedicatedServer, NULL); while( Itr != NULL ) { if( sscanf(Itr, "%s %s", Domain, Server) < 2 ) { INFO("Invalid Option in `DedicatedServer' : %s\n", Itr); continue; } INFO("Add a dedicated Server %s for %s\n", Server, Domain); AddressChunk_AddADedicatedAddress_FromString(&Addresses, Domain, Server); Itr = StringList_GetNext(DedicatedServer, Itr); } StringList_Free(DedicatedServer); return 0; }
int StringChunk_Init(StringChunk *dl, int InitialCount /* For no-wildcard domain */) { if( StringList_Init(&(dl -> List), NULL, 0) != 0 ) { return -1; } if( HashTable_Init(&(dl -> List_Pos), sizeof(EntryForString), InitialCount, NULL) != 0 ) { StringList_Free(&(dl -> List)); return -2; } if( StringList_Init(&(dl -> List_W), NULL, 0) != 0 ) { StringList_Free(&(dl -> List)); HashTable_Free(&(dl -> List_Pos)); return -3; } if( Array_Init(&(dl -> List_W_Pos), sizeof(EntryForString), 0, FALSE, NULL) != 0 ) { StringList_Free(&(dl -> List)); HashTable_Free(&(dl -> List_Pos)); StringList_Free(&(dl -> List_W)); return -4; } if( ExtendableBuffer_Init(&(dl -> AdditionalDataChunk), 0, -1) != 0 ) { StringList_Free(&(dl -> List)); HashTable_Free(&(dl -> List_Pos)); StringList_Free(&(dl -> List_W)); Array_Free(&(dl -> List_W_Pos)); return -5; } return 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); }
int InitAddress(void) { StringList *tcpaddrs = ConfigGetStringList(&ConfigInfo, "TCPServer"); StringList *udpaddrs = ConfigGetStringList(&ConfigInfo, "UDPServer"); const char *Itr = NULL; if( AddressChunk_Init(&Addresses) != 0 ) { return -1; } Itr = StringList_GetNext(tcpaddrs, NULL); while( Itr != NULL ) { if( AddressChunk_AddATCPAddress_FromString(&Addresses, Itr) != 0 ) { INFO("Bad address : %s\n", Itr); } else { DEBUG_FILE("Add TCP address : %s\n", Itr); } Itr = StringList_GetNext(tcpaddrs, Itr); } Itr = StringList_GetNext(udpaddrs, NULL); while( Itr != NULL ) { if( AddressChunk_AddAUDPAddress_FromString(&Addresses, Itr) != 0 ) { INFO("Bad address : %s\n", Itr); } else { DEBUG_FILE("Add UDP address : %s\n", Itr); } Itr = StringList_GetNext(udpaddrs, Itr); } ParallelQuery = ConfigGetBoolean(&ConfigInfo, "ParallelQuery"); if( ParallelQuery == TRUE ) { int NumberOfAddr; int AddrLen; sa_family_t SubFamily; struct sockaddr *OneAddr; NumberOfAddr = StringList_Count(udpaddrs); if( NumberOfAddr <= 0 ) { ERRORMSG("No UDP server specified, cannot use parallel query.\n") ParallelQuery = FALSE; } else { DEBUG_FILE("Enable parallel query.\n"); AddressChunk_GetOneUDPBySubscript(&Addresses, &MainFamily, 0); if( MainFamily == AF_INET ) { AddrLen = sizeof(struct sockaddr); DEBUG_FILE("Parallel query servers family IPv4.\n"); } else { AddrLen = sizeof(struct sockaddr_in6); DEBUG_FILE("Parallel query servers family IPv6.\n"); } Array_Init(&Addresses_Array, AddrLen, NumberOfAddr, FALSE, NULL); while( NumberOfAddr != 0 ) { OneAddr = AddressChunk_GetOneUDPBySubscript(&Addresses, &SubFamily, NumberOfAddr - 1); if( OneAddr != NULL && SubFamily == MainFamily ) { Array_PushBack(&Addresses_Array, OneAddr, NULL); } --NumberOfAddr; } } } StringList_Free(tcpaddrs); StringList_Free(udpaddrs); return LoadDedicatedServer(); }