summaryrefslogtreecommitdiff
path: root/src/libs6/ftrigr_subscribe.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
commit90b12bd71bb9fc79a4640b9112c13ef529d0196a (patch)
tree523b3f4ee2969e7a729bab2ba749c4b924ae62af /src/libs6/ftrigr_subscribe.c
downloads6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.tar.xz
Initial commit
Diffstat (limited to 'src/libs6/ftrigr_subscribe.c')
-rw-r--r--src/libs6/ftrigr_subscribe.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/libs6/ftrigr_subscribe.c b/src/libs6/ftrigr_subscribe.c
new file mode 100644
index 0000000..d645931
--- /dev/null
+++ b/src/libs6/ftrigr_subscribe.c
@@ -0,0 +1,43 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/uint16.h>
+#include <skalibs/uint32.h>
+#include <skalibs/siovec.h>
+#include <skalibs/tai.h>
+#include <skalibs/gensetdyn.h>
+#include <skalibs/skaclient.h>
+#include <s6/ftrigr.h>
+
+uint16 ftrigr_subscribe (ftrigr_t *a, char const *path, char const *re, uint32 options, tain_t const *deadline, tain_t *stamp)
+{
+ unsigned int pathlen = str_len(path) ;
+ unsigned int relen = str_len(re) ;
+ unsigned int i ;
+ char err ;
+ char tmp[15] = "--L" ;
+ siovec_t v[3] = { { .s = tmp, .len = 15 }, { .s = (char *)path, .len = pathlen + 1 }, { .s = (char *)re, .len = relen + 1 } } ;
+ if (!gensetdyn_new(&a->data, &i)) return 0 ;
+ uint16_pack_big(tmp, (uint16)i) ;
+ uint32_pack_big(tmp+3, options) ;
+ uint32_pack_big(tmp+7, (uint32)pathlen) ;
+ uint32_pack_big(tmp+11, (uint32)relen) ;
+ if (!skaclient_sendv(&a->connection, v, 3, &skaclient_default_cb, &err, deadline, stamp))
+ {
+ gensetdyn_delete(&a->data, i) ;
+ return 0 ;
+ }
+ if (err)
+ {
+ gensetdyn_delete(&a->data, i) ;
+ return (errno = err, 0) ;
+ }
+ {
+ register ftrigr1_t *p = GENSETDYN_P(ftrigr1_t, &a->data, i) ;
+ p->options = options ;
+ p->state = FR1STATE_LISTENING ;
+ p->count = 0 ;
+ p->what = 0 ;
+ }
+ return (uint16)(i+1) ;
+}