Delete/replace/add hosts within config reading loop.
This commit is contained in:
parent
fbe5e18f9d
commit
ccb0e90d3b
9
main.c
9
main.c
@ -63,6 +63,10 @@ void blockHost(char *host)
|
|||||||
fclose(hostsFile);
|
fclose(hostsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteHost(char *host)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void showHosts()
|
void showHosts()
|
||||||
{
|
{
|
||||||
@ -111,16 +115,18 @@ int update_hosts_file() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
replacehost(ptr->data, buf);
|
||||||
strcpy(ptr->data, buf);
|
strcpy(ptr->data, buf);
|
||||||
prev = ptr;
|
prev = ptr;
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
} else {
|
} else {
|
||||||
|
blockHost(buf);
|
||||||
linkedlist_add(&hosts, buf);
|
linkedlist_add(&hosts, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this case, the list got chopped off, we need to reset pointers and free the rest of our list.
|
// In this case, the list got chopped off, we need to reset pointers and free the rest of our list.
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL && prev != NULL) {
|
||||||
prev->next = NULL;
|
prev->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +135,7 @@ int update_hosts_file() {
|
|||||||
while (ptr != NULL) {
|
while (ptr != NULL) {
|
||||||
prev = ptr;
|
prev = ptr;
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
deleteHost(prev->data);
|
||||||
free(prev->data);
|
free(prev->data);
|
||||||
free(prev);
|
free(prev);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user