diff options
Diffstat (limited to 'src/libs6/ftrigr_update.c')
-rw-r--r-- | src/libs6/ftrigr_update.c | 57 |
1 files changed, 1 insertions, 56 deletions
diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c index f97535d..674d8cb 100644 --- a/src/libs6/ftrigr_update.c +++ b/src/libs6/ftrigr_update.c @@ -1,66 +1,11 @@ /* ISC license. */ -#include <sys/types.h> #include <stdint.h> -#include <errno.h> -#include <skalibs/gccattributes.h> -#include <skalibs/error.h> -#include <skalibs/uint16.h> #include <skalibs/genalloc.h> -#include <skalibs/gensetdyn.h> -#include <skalibs/unixmessage.h> -#include <skalibs/skaclient.h> #include <s6/ftrigr.h> -static inline int appears (uint16_t, uint16_t const *, size_t) gccattr_pure ; - -static inline int appears (uint16_t id, uint16_t const *list, size_t len) -{ - while (len) if (id == list[--len]) return 1 ; - return 0 ; -} - -static int msghandler (unixmessage_t const *m, void *context) -{ - ftrigr_t *a = (ftrigr_t *)context ; - ftrigr1_t *p ; - int addit = 1 ; - uint16_t id ; - if (m->len != 4 || m->nfds) return (errno = EPROTO, 0) ; - uint16_unpack_big(m->s, &id) ; - p = GENSETDYN_P(ftrigr1_t, &a->data, id) ; - if (!p) return 1 ; - if (p->state != FR1STATE_LISTENING) return (errno = EINVAL, 0) ; - if (!genalloc_readyplus(uint16_t, &a->list, 1)) return 0 ; - switch (m->s[2]) - { - case 'd' : - if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; - p->state = FR1STATE_WAITACK ; - break ; - case '!' : - if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; - if (p->options & FTRIGR_REPEAT) - { - if (p->what.len > 1 - && appears(id+1, genalloc_s(uint16_t, &a->list), genalloc_len(uint16_t, &a->list))) - addit = 0 ; - } - else p->state = FR1STATE_WAITACKDATA ; - break ; - default : return (errno = EPROTO, 0) ; - } - if (addit) - { - id++ ; genalloc_append(uint16_t, &a->list, &id) ; - } - return 1 ; -} - int ftrigr_update (ftrigr_t *a) { - int r ; genalloc_setlen(uint16_t, &a->list, 0) ; - r = skaclient_update(&a->connection, &msghandler, a) ; - return r < 0 ? r : (int)genalloc_len(uint16_t, &a->list) ; + return ftrigr_updateb(a) ; } |