#include #include #include #include #include #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) { }