diff options
author | James <31272717+gpd-pocket-hacker@users.noreply.github.com> | 2020-10-31 18:25:41 +0000 |
---|---|---|
committer | James <31272717+gpd-pocket-hacker@users.noreply.github.com> | 2020-10-31 19:32:32 +0000 |
commit | c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61 (patch) | |
tree | 9866aac3d1c354fb6f042d640b4fa470ee8809d3 /rx.c | |
parent | 232cf21c35c79458969fd661d18ca779c5418c2e (diff) | |
download | galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.gz galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.bz2 galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.zip |
split out rx and add syslog support
Diffstat (limited to 'rx.c')
-rw-r--r-- | rx.c | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <syslog.h> + +#include "sia.h" + +static void msg (char *account, char *event, char *ascii, int log) +{ + if (log) + syslog (LOG_WARNING, "SIA: %s %64s %s", account, event, ascii); + + printf ("%s %64s %s\n", account, event, ascii); +} + + +int new_block (int fd, SIA_Block *b, int log) +{ + static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */ + + static char account[SIA_MAX_DATA_LENGTH + 1]; + static char event[SIA_MAX_DATA_LENGTH + 1]; + static char ascii[SIA_MAX_DATA_LENGTH + 1]; + + unsigned len = sia_data_length (b); + + if (sia_ack_if_needed (fd, b)) + return -1; + + switch (b->function) { + case SIA_FN_ACCOUNT_ID: + memcpy (account, b->data, len); + account[len] = 0; + break; + + case SIA_FN_NEW_EVENT: + case SIA_FN_OLD_EVENT: + memcpy (event, b->data, len); + event[len] = 0; + + if (!have_ascii_messages) msg (account, event, "", log); + + break; + + case SIA_FN_ASCII: + have_ascii_messages = 1; + memcpy (ascii, b->data, len); + ascii[len] = 0; + + msg (account, event, ascii, log); + break; + } + + return 0; +} + +void periodic_task (void) +{ +} + + |