feature/delete-host: Delete a hosts from the hosts file. #4

Manually merged
jacob.windle merged 3 commits from feature/delete-host into master 2020-01-17 13:24:27 +00:00
Showing only changes of commit 31186418c3 - Show all commits

16
main.c
View File

@ -14,13 +14,6 @@
#define ARG_IS(argname) (strcmp(argv[i], argname) == 0)
/**
* TODO: Add config file reading for daemonization.
* TODO: Allow daemonized process to call file reading/editing routines at will.
* TODO: Generalized routine for reading through a file and replacing a line.
* TODO: Generalized routine for reading a file.
*/
/** GLOBALS **/
// Our rule we use to blackhole domains
const char *blockString = "0.0.0.0 ";
@ -107,8 +100,7 @@ void blockHost(char *host)
fclose(hostsFile);
}
void deleteHost(char *host)
{
void deleteHost(char *host) {
modifyHostsFile(host, NULL, 1);
}
@ -163,7 +155,7 @@ int update_hosts_file() {
return 0;
}
}
replacehost(ptr->data, buf);
replaceHost(ptr->data, buf);
strcpy(ptr->data, buf);
prev = ptr;
ptr = ptr->next;
@ -258,12 +250,12 @@ int main(int argc, char **argv)
}
// Replaces a host
else if (ARG_IS("edit")) {
replacehost(argv[i + 1], argv[i + 2], 0);
replaceHost(argv[i + 1], argv[i + 2]);
i += 2;
}
// Deletes a host.
else if (ARG_IS("delete")) {
fprintf(stdout, "Soon to be implemented!\n");
deleteHost(argv[i+1]);
}
// Shows usage.
else if (ARG_IS("-h")) {