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; }
const char *StringChunk_Enum(StringChunk *dl, const char *Start, char **Data) { const char *str; str = StringList_GetNext(&(dl -> List), Start); if( str == NULL ) { str = StringList_GetNext(&(dl -> List_W), Start); } if( str == NULL ) { return NULL; } StringChunk_Match(dl, str, NULL, Data); return str; }
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(); }
int StaticHosts_Init(ConfigFileInfo *ConfigInfo) { int IPv4Count = 0, IPv6Count = 0, CNameCount = 0, ExcludedCount = 0; StringList *AppendHosts = ConfigGetStringList(ConfigInfo, "AppendHosts"); const char *Itr; char Buffer[2 * DOMAIN_NAME_LENGTH_MAX + 2]; if( AppendHosts == NULL ) { return -1; } if( Hosts_InitContainer(&MainContainer) != 0 ) { return -1; } Itr = StringList_GetNext(AppendHosts, NULL); while( Itr != NULL ) { if( strlen(Itr) > sizeof(Buffer) - 1 ) { ERRORMSG("Hosts is too long : %s\n", Buffer); } else { strcpy(Buffer, Itr); Buffer[sizeof(Buffer) - 1] = '\0'; switch( Hosts_LoadFromMetaLine(&MainContainer, Buffer) ) { case HOSTS_TYPE_A: ++IPv4Count; break; case HOSTS_TYPE_AAAA: ++IPv6Count; break; case HOSTS_TYPE_CNAME: ++CNameCount; break; case HOSTS_TYPE_EXCLUEDE: ++ExcludedCount; break; default: break; } } Itr = StringList_GetNext(AppendHosts, Itr); } INFO("Loading Appendhosts completed, %d IPv4 Hosts, %d IPv6 Hosts, %d CName Redirections, %d items are excluded.\n", IPv4Count, IPv6Count, CNameCount, ExcludedCount); Inited = TRUE; return 0; }