Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix Third Party Filtering #433

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make Budlist and type filter look into 3rd party
  • Loading branch information
F4FXL committed Dec 3, 2022
commit 2a7bc246f2f462b0444e84478903e02465e42b6d
53 changes: 24 additions & 29 deletions src/pfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void next_token (pfstate_t *pf);
static void print_error (pfstate_t *pf, char *msg);

static int filt_bodgu (pfstate_t *pf, char *pattern);
static int filt_t (pfstate_t *pf);
static int filt_t (pfstate_t *pf, char * typeChar);
static int filt_r (pfstate_t *pf, char *sdist);
static int filt_s (pfstate_t *pf);
static int filt_i (pfstate_t *pf);
Expand Down Expand Up @@ -200,7 +200,6 @@ int pfilter (int from_chan, int to_chan, char *filter, packet_t pp, int is_aprs)
pfstate_t pfstate;
char *p;
int result;
char * infop = NULL;


assert (from_chan >= 0 && from_chan <= MAX_CHANS);
Expand Down Expand Up @@ -233,21 +232,6 @@ int pfilter (int from_chan, int to_chan, char *filter, packet_t pp, int is_aprs)
}
}

(void) ax25_get_info (pp, (unsigned char **)(&infop));
assert (infop != NULL);
if (*infop == '}') {
// We have a 3d party packet, dig inside it to get the actual type.
packet_t pp_payload = ax25_from_text ((char*)infop+1, 0);
if (pp_payload == NULL) {
print_error (&pfstate, "Invalid third party payload\n");
return (0);
}

result = pfilter(from_chan, to_chan, filter, pp_payload, is_aprs);
ax25_delete(pp_payload);
return result;
}

pfstate.pp = pp;
pfstate.is_aprs = is_aprs;

Expand Down Expand Up @@ -564,13 +548,11 @@ static int parse_filter_spec (pfstate_t *pf)

else if (pf->token_str[0] == 'b' && ispunct(pf->token_str[1])) {
/* Budlist - source address */
char addr[AX25_MAX_ADDR_LEN];
ax25_get_addr_with_ssid (pf->pp, AX25_SOURCE, addr);
result = filt_bodgu (pf, addr);
result = filt_bodgu (pf, pf->decoded.g_src);

if (s_debug >= 2) {
text_color_set(DW_COLOR_DEBUG);
dw_printf (" %s returns %s for %s\n", pf->token_str, bool2text(result), addr);
dw_printf (" %s returns %s for %s\n", pf->token_str, bool2text(result), pf->decoded.g_src);
}
}

Expand Down Expand Up @@ -688,15 +670,12 @@ static int parse_filter_spec (pfstate_t *pf)
/* t - type: position, weather, etc. */

else if (pf->token_str[0] == 't' && ispunct(pf->token_str[1])) {

result = filt_t (pf);
char typeChar = 0;
result = filt_t (pf, &typeChar);

if (s_debug >= 2) {
char *infop = NULL;
(void) ax25_get_info (pf->pp, (unsigned char **)(&infop));

text_color_set(DW_COLOR_DEBUG);
dw_printf (" %s returns %s for %c data type indicator\n", pf->token_str, bool2text(result), *infop);
dw_printf (" %s returns %s for %c data type indicator\n", pf->token_str, bool2text(result), typeChar);
}
}

Expand Down Expand Up @@ -874,18 +853,33 @@ int is_telem_metadata (char *infop)
}


static int filt_t (pfstate_t *pf)
static int filt_t (pfstate_t *pf, char * typeChar)
{
char src[AX25_MAX_ADDR_LEN];
char *infop = NULL;
char *f;
int isThirdParty = 0;

memset (src, 0, sizeof(src));
ax25_get_addr_with_ssid (pf->pp, AX25_SOURCE, src);
(void) ax25_get_info (pf->pp, (unsigned char **)(&infop));

if (*infop == '}') {
// We have a 3d party packet, dig inside it to get the actual type.
packet_t pp_payload = ax25_from_text ((char*)infop+1, 0);
if (pp_payload == NULL) {
print_error (pf, "Invalid third party payload\n");
return (0);
}
(void) ax25_get_info (pf->pp, (unsigned char **)(&infop));
ax25_delete(pp_payload);
isThirdParty = 1;
}

assert (infop != NULL);

*typeChar = *infop;

for (f = pf->token_str + 2; *f != '\0'; f++) {
switch (*f) {

Expand Down Expand Up @@ -937,7 +931,8 @@ static int filt_t (pfstate_t *pf)
break;

case 'h': /* third party Header - my extension */
if (*infop == '}') return (1);
*typeChar = '}';
return (isThirdParty);
break;

case 'w': /* Weather */
Expand Down