diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-01 19:36:38 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-01 19:36:38 +0000 |
commit | 69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd (patch) | |
tree | 9c97923869ff4f56717d7e0ac97c8588f816c798 /src/libwpactrl/wpactrl_xchg_event.c | |
parent | 22a1dc61ef8e4e1c98e3a088db1dbc84d424c7a7 (diff) | |
download | bcnm-69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd.tar.xz |
Flesh out libwpactrl
Diffstat (limited to 'src/libwpactrl/wpactrl_xchg_event.c')
-rw-r--r-- | src/libwpactrl/wpactrl_xchg_event.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libwpactrl/wpactrl_xchg_event.c b/src/libwpactrl/wpactrl_xchg_event.c new file mode 100644 index 0000000..6d25295 --- /dev/null +++ b/src/libwpactrl/wpactrl_xchg_event.c @@ -0,0 +1,42 @@ +/* ISC license. */ + +#include <string.h> +#include <skalibs/stralloc.h> +#include <bcnm/wpactrl.h> + +static inline size_t wpactrl_findmsg (wpactrl_t *a, char const *filter) +{ + size_t filterlen = strlen(filter) ; + size_t i = 0 ; + while (i < a->data.len) + { + if (!strncmp(a->data.s + i, filter, filterlen)) break ; + i += strlen(a->data.s + i) + 1 ; + } + return i ; +} + +int wpactrl_xchg_event (wpactrl_t *a, wpactrl_xchg_t *dt, tain_t *stamp) +{ + size_t pos, len ; + if (dt->i >= dt->n) return 2 ; + pos = wpactrl_findmsg(a, dt->tab[dt->i].filter) ; + if (pos >= a->data.len) return 0 ; + dt->sa.len = 0 ; + len = strlen(a->data.s + pos) + 1 ; + if (dt->i == dt->n - 1) + { + if (!stralloc_catb(&dt->sa, a->data.s + pos, len)) return -1 ; + memmove(a->data.s + pos, a->data.s + pos + len, a->data.len - len) ; + a->data.len -= len ; + dt->status = 0 ; + wpactrl_filter_remove(a, dt->tab[dt->i].filter) ; + return 1 ; + } + if (!(*dt->tab[dt->i].f)(a, a->data.s + pos, len - 1, dt->aux, stamp)) return -1 ; + memmove(a->data.s + pos, a->data.s + pos + len, a->data.len - len) ; + a->data.len -= len ; + wpactrl_filter_remove(a, dt->tab[dt->i].filter) ; + if (!wpactrl_filter_add(a, dt->tab[++dt->i].filter)) return -1 ; + return 0 ; +} |