1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-24 17:03:24 +01:00

Merge pull request #80 from viric/dhtservers

Fallback to loading /usr/share/toxic/DHTservers.
This commit is contained in:
JFreegman 2014-02-24 02:17:14 -05:00
commit b308e19e6b

View File

@ -146,11 +146,14 @@ static char servers[MAXSERVERS][SERVERLEN];
static uint16_t ports[MAXSERVERS]; static uint16_t ports[MAXSERVERS];
static uint8_t keys[MAXSERVERS][TOX_CLIENT_ID_SIZE]; static uint8_t keys[MAXSERVERS][TOX_CLIENT_ID_SIZE];
int serverlist_load(void) static int serverlist_load(const char *filename)
{ {
FILE *fp = NULL; FILE *fp = NULL;
fp = fopen(SRVLIST_FILE, "r"); if (!filename)
return 1;
fp = fopen(filename, "r");
if (fp == NULL) if (fp == NULL)
return 1; return 1;
@ -213,9 +216,15 @@ int init_connection(Tox *m)
*/ */
if (!init_connection_serverlist_loaded) { if (!init_connection_serverlist_loaded) {
init_connection_serverlist_loaded = 1; init_connection_serverlist_loaded = 1;
int res = serverlist_load(); int res = serverlist_load(SRVLIST_FILE);
if (res)
{
// Fallback on the provided DHTServers in /usr/share,
// so new starts of toxic will connect to the DHT.
serverlist_load(PACKAGE_DATADIR "/DHTservers");
if (res) if (res)
return res; return res;
}
if (!linecnt) if (!linecnt)
return 4; return 4;
@ -509,9 +518,6 @@ int main(int argc, char *argv[])
} }
} }
if (config_err) {
SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers");
} else {
SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
if (SRVLIST_FILE != NULL) { if (SRVLIST_FILE != NULL) {
strcpy(SRVLIST_FILE, user_config_dir); strcpy(SRVLIST_FILE, user_config_dir);
@ -522,7 +528,6 @@ int main(int argc, char *argv[])
fprintf(stderr, "malloc() failed. Aborting...\n"); fprintf(stderr, "malloc() failed. Aborting...\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
}
free(user_config_dir); free(user_config_dir);