Skip to content

Commit 69ecc2c

Browse files
authored
Merge pull request #1559 from pi-hole/new/parseList
Add list parsing feature for gravity
2 parents 9b45d5c + 1bcee5f commit 69ecc2c

File tree

5 files changed

+444
-1
lines changed

5 files changed

+444
-1
lines changed

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ set(sources
128128
FTL.h
129129
gc.c
130130
gc.h
131+
gravity-tools.c
132+
gravity-tools.h
131133
log.c
132134
log.h
133135
main.c

src/args.c

+26-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "shmem.h"
3333
// LUA dependencies
3434
#include "lua/ftl_lua.h"
35+
// gravity_parseList()
36+
#include "gravity-tools.h"
3537
// run_dhcp_discover()
3638
#include "tools/dhcp-discover.h"
3739
// run_arp_scan()
@@ -126,7 +128,15 @@ static const char __attribute__ ((pure)) *cli_color(const char *color)
126128
return is_term() ? color : "";
127129
}
128130

129-
static inline bool strEndsWith(const char *input, const char *end){
131+
// Go back to beginning of line and erase to end of line if STDOUT is a terminal
132+
const char __attribute__ ((pure)) *cli_over(void)
133+
{
134+
// \x1b[K is the ANSI escape sequence for "erase to end of line"
135+
return is_term() ? "\r\x1b[K" : "\r";
136+
}
137+
138+
static inline bool strEndsWith(const char *input, const char *end)
139+
{
130140
return strcmp(input + strlen(input) - strlen(end), end) == 0;
131141
}
132142

@@ -165,6 +175,21 @@ void parse_args(int argc, char* argv[])
165175
(argc > 1 && strEndsWith(argv[1], ".db")))
166176
exit(sqlite3_shell_main(argc, argv));
167177

178+
// If the first argument is "gravity" (e.g., /usr/bin/pihole-FTL gravity),
179+
// we offer some specialized gravity tools
180+
if(argc > 1 && strcmp(argv[1], "gravity") == 0)
181+
{
182+
// pihole-FTL gravity parseList <infile> <outfile> <adlistID>
183+
if(argc == 6 && strcmp(argv[2], "parseList") == 0)
184+
{
185+
// Parse the given list and write the result to the given file
186+
exit(gravity_parseList(argv[3], argv[4], argv[5]));
187+
}
188+
189+
printf("Incorrect usage of pihole-FTL gravity subcommand\n");
190+
exit(EXIT_FAILURE);
191+
}
192+
168193
// DHCP discovery mode
169194
if(argc > 1 && strcmp(argv[1], "dhcp-discover") == 0)
170195
{

src/args.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const char *cli_qst(void) __attribute__ ((const));
2323
const char *cli_done(void) __attribute__ ((pure));
2424
const char *cli_bold(void) __attribute__ ((pure));
2525
const char *cli_normal(void) __attribute__ ((pure));
26+
const char *cli_over(void) __attribute__ ((pure));
2627

2728
// defined in dnsmasq_interface.c
2829
int check_struct_sizes(void);

0 commit comments

Comments
 (0)