static gboolean _parse_transport_info(SnmpTrapdHeaderParser *self) { if(!scan_expect_char(self->input, (gint *) self->input_len, '[')) return FALSE; _skip_spaces(self); const gchar *transport_info_start = *self->input; const gchar *transport_info_end = strchr(transport_info_start, '\n'); if (!transport_info_end) return FALSE; while(*transport_info_end != ']') { --transport_info_end; if(transport_info_end == transport_info_start) return FALSE; } gsize transport_info_len = transport_info_end - transport_info_start; snmptrapd_nv_context_add_name_value(self->nv_context, "transport_info", transport_info_start, transport_info_len); *self->input_len -= (transport_info_end + 1) - *self->input; *self->input = transport_info_end + 1; return TRUE; }
gboolean scan_bsd_timestamp(const gchar **buf, gint *left, struct tm *tm) { /* RFC 3164 timestamp, expected format: MMM DD HH:MM:SS ... */ if (!scan_month_abbrev(buf, left, &tm->tm_mon) || !scan_expect_char(buf, left, ' ') || !scan_int(buf, left, 2, &tm->tm_mday) || !scan_expect_char(buf, left, ' ') || !scan_int(buf, left, 2, &tm->tm_hour) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_min) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_sec)) return FALSE; return TRUE; }
gboolean scan_pix_timestamp(const gchar **buf, gint *left, struct tm *tm) { /* PIX/ASA timestamp, expected format: MMM DD YYYY HH:MM:SS */ if (!scan_month_abbrev(buf, left, &tm->tm_mon) || !scan_expect_char(buf, left, ' ') || !scan_int(buf, left, 2, &tm->tm_mday) || !scan_expect_char(buf, left, ' ') || !scan_int(buf, left, 4, &tm->tm_year) || !scan_expect_char(buf, left, ' ') || !scan_int(buf, left, 2, &tm->tm_hour) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_min) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_sec)) return FALSE; tm->tm_year -= 1900; return TRUE; }
/* this function parses the date/time portion of an ISODATE */ gboolean scan_iso_timestamp(const gchar **buf, gint *left, struct tm *tm) { /* YYYY-MM-DDTHH:MM:SS */ if (!scan_int(buf, left, 4, &tm->tm_year) || !scan_expect_char(buf, left, '-') || !scan_int(buf, left, 2, &tm->tm_mon) || !scan_expect_char(buf, left, '-') || !scan_int(buf, left, 2, &tm->tm_mday) || !scan_expect_char(buf, left, 'T') || !scan_int(buf, left, 2, &tm->tm_hour) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_min) || !scan_expect_char(buf, left, ':') || !scan_int(buf, left, 2, &tm->tm_sec)) return FALSE; tm->tm_year -= 1900; tm->tm_mon -= 1; return TRUE; }
static inline gboolean _expect_char(SnmpTrapdHeaderParser *self, gchar c) { return scan_expect_char(self->input, (gint *) self->input_len, c); }