Skip to content

Commit

Permalink
Merge pull request #181 from pi-hole/release/v2.13.1
Browse files Browse the repository at this point in the history
Pi-hole FTL v2.13.1
  • Loading branch information
dschaper authored Dec 28, 2017
2 parents 07b1275 + 8352566 commit 1e45569
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
15 changes: 11 additions & 4 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "version") == 0)
{
char version[] = GIT_VERSION;
const char * version = GIT_VERSION;
// Check if version is of format vX.YY
// '.' can never be part of a commit hash
if(strstr(version, ".") != NULL)
Expand All @@ -90,7 +90,15 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-b") == 0 ||
strcmp(argv[i], "branch") == 0)
{
printf("%s\n",GIT_BRANCH);
const char * branch = GIT_BRANCH;
const char * version = GIT_VERSION;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";
printf("%s\n",branch);
exit(EXIT_SUCCESS);
}

Expand Down Expand Up @@ -123,8 +131,7 @@ void parse_args(int argc, char* argv[])
}

// List of implemented arguments
if(strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "help") == 0)
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "help") == 0 || strcmp(argv[i], "--help") == 0)
{
printf("pihole-FTL - The Pi-hole FTL engine\n\n");
printf("Usage: sudo service pihole-FTL <action>\n");
Expand Down
32 changes: 30 additions & 2 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,38 @@ int countlineswith(const char* str, const char* fname)
}

// Search through file
// getline reads a string from the specified file up to either a newline character or EOF
// getline reads a string from the specified file up to either a
// newline character or EOF
while(getline(&buffer, &size, fp) != -1)
if((strstr(buffer, str)) != NULL)
{
// Strip potential newline character at the end of line we just read
if(buffer[strlen(buffer)-1] == '\n')
buffer[strlen(buffer)-1] = '\0';

// Search for exact match
if(strcmp(buffer, str) == 0)
{
found++;
continue;
}

// If line starts with *, search for partial match of
// needle "buffer+1" in haystack "str"
if(buffer[0] == '*')
{
char * buf = strstr(str, buffer+1);
// The strstr() function finds the first occurrence of
// the substring buffer+1 in the string str.
// These functions return a pointer to the beginning of
// the located substring, or NULL if the substring is not
// found. Hence, we compare the length of the substring to
// the wildcard entry to rule out the possiblity that
// there is anything behind the wildcard. This avoids that given
// "*example.com" "example.com.xxxxx" would also match.
if(buf != NULL && strlen(buf) == strlen(buffer+1))
found++;
}
}

// Free allocated memory
if(buffer != NULL)
Expand Down
14 changes: 11 additions & 3 deletions request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,19 @@ void getVersion(int *sock)
{
char server_message[SOCKETBUFFERLEN];

char version[] = GIT_VERSION;
const char * version = GIT_VERSION;
const char * branch = GIT_BRANCH;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";

if(strstr(version, ".") != NULL)
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", GIT_VERSION, GIT_TAG, GIT_BRANCH, GIT_DATE);
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", version, GIT_TAG, branch, GIT_DATE);
else
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", GIT_HASH, GIT_TAG, GIT_BRANCH, GIT_DATE);
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", GIT_HASH, GIT_TAG, branch, GIT_DATE);
swrite(server_message, *sock);

if(debugclients)
Expand Down

0 comments on commit 1e45569

Please sign in to comment.