#include #include #include #include #include #include "sia.h" #include "email.h" static void msg (char *account, char *event, char *ascii, int log, const char *email) { char body[256]; char subject[256]; snprintf (body, sizeof (body) - 1, "%s %64s %s", account, event, ascii); body[sizeof (body) - 1] = 0; if (log) syslog (LOG_WARNING, "SIA: %s", body); printf ("%s\n", body); if (!email) return; if (strstr (body, "HEARTBT")) return; snprintf (subject, sizeof (subject) - 1, "Galaxy SIA: %s", ascii); send_email (email, subject, body); } int new_block (int fd, SIA_Block *b, int log, const char *email) { 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, email); break; case SIA_FN_ASCII: have_ascii_messages = 1; memcpy (ascii, b->data, len); ascii[len] = 0; msg (account, event, ascii, log, email); break; } return 0; } void periodic_task (void) { }