Cleanup, implements delete functionality

pull/4/head
Jacob Windle 2020-01-17 08:21:19 -05:00
parent fac37b8b40
commit 31186418c3
1 changed files with 4 additions and 12 deletions

16
main.c
View File

@ -14,13 +14,6 @@
#define ARG_IS(argname) (strcmp(argv[i], argname) == 0) #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 **/ /** GLOBALS **/
// Our rule we use to blackhole domains // Our rule we use to blackhole domains
const char *blockString = "0.0.0.0 "; const char *blockString = "0.0.0.0 ";
@ -107,8 +100,7 @@ void blockHost(char *host)
fclose(hostsFile); fclose(hostsFile);
} }
void deleteHost(char *host) void deleteHost(char *host) {
{
modifyHostsFile(host, NULL, 1); modifyHostsFile(host, NULL, 1);
} }
@ -163,7 +155,7 @@ int update_hosts_file() {
return 0; return 0;
} }
} }
replacehost(ptr->data, buf); replaceHost(ptr->data, buf);
strcpy(ptr->data, buf); strcpy(ptr->data, buf);
prev = ptr; prev = ptr;
ptr = ptr->next; ptr = ptr->next;
@ -258,12 +250,12 @@ int main(int argc, char **argv)
} }
// Replaces a host // Replaces a host
else if (ARG_IS("edit")) { else if (ARG_IS("edit")) {
replacehost(argv[i + 1], argv[i + 2], 0); replaceHost(argv[i + 1], argv[i + 2]);
i += 2; i += 2;
} }
// Deletes a host. // Deletes a host.
else if (ARG_IS("delete")) { else if (ARG_IS("delete")) {
fprintf(stdout, "Soon to be implemented!\n"); deleteHost(argv[i+1]);
} }
// Shows usage. // Shows usage.
else if (ARG_IS("-h")) { else if (ARG_IS("-h")) {