int testcase_replace(const gchar *log, const gchar *re, gchar *replacement, const gchar *expected_result, const gint matcher_flags, LogMatcher *m) { LogMessage *msg; LogTemplate *r; gchar *result; gssize length; gchar buf[1024]; gssize msglen; NVHandle nonasciiz = log_msg_get_value_handle("NON-ASCIIZ"); const gchar *value; GSockAddr *sa; sa = g_sockaddr_inet_new("10.10.10.10", 1010); msg = log_msg_new(log, strlen(log), sa, &parse_options); g_sockaddr_unref(sa); /* NOTE: we test how our matchers cope with non-zero terminated values. We don't change message_len, only the value */ g_snprintf(buf, sizeof(buf), "%sAAAAAAAAAAAA", log_msg_get_value(msg, LM_V_MESSAGE, &msglen)); log_msg_set_value(msg, log_msg_get_value_handle("MESSAGE2"), buf, -1); /* add a non-zero terminated indirect value which contains the whole message */ log_msg_set_value_indirect(msg, nonasciiz, log_msg_get_value_handle("MESSAGE2"), 0, 0, msglen); log_matcher_set_flags(m, matcher_flags); log_matcher_compile(m, re); r = log_template_new(configuration, NULL); log_template_compile(r, replacement, NULL); NVTable *nv_table = nv_table_ref(msg->payload); value = log_msg_get_value(msg, nonasciiz, &msglen); result = log_matcher_replace(m, msg, nonasciiz, value, msglen, r, &length); value = log_msg_get_value(msg, nonasciiz, &msglen); nv_table_unref(nv_table); if (strncmp(result ? result : value, expected_result, result ? length : msglen) != 0) { fprintf(stderr, "Testcase failure. pattern=%s, result=%.*s, expected=%s\n", re, (gint) length, result ? result : value, expected_result); exit(1); } g_free(result); log_template_unref(r); log_matcher_unref(m); log_msg_unref(msg); return 0; }
void log_rewrite_subst_process(LogRewrite *s, LogMessage **pmsg, const LogPathOptions *path_options) { LogRewriteSubst *self = (LogRewriteSubst *) s; const gchar *value; gchar *new_value; gssize length; gssize new_length = -1; value = log_msg_get_value(*pmsg, self->super.value_handle, &length); log_msg_make_writable(pmsg, path_options); new_value = log_matcher_replace(self->matcher, *pmsg, self->super.value_handle, value, length, self->replacement, &new_length); if (new_value) { log_msg_set_value(*pmsg, self->super.value_handle, new_value, new_length); } g_free(new_value); }
void log_rewrite_subst_process(LogRewrite *s, LogMessage *msg) { LogRewriteSubst *self = (LogRewriteSubst *) s; GError *regexp_error; const gchar *value; gchar *new_value; regexp_error = NULL; gssize length; gssize new_length = -1; value = log_msg_get_value(msg, self->super.value_handle, &length); new_value = log_matcher_replace(self->matcher, msg, self->super.value_handle, value, length, self->replacement, &new_length); if (new_value) { log_msg_set_value(msg, self->super.value_handle, new_value, new_length); } g_free(new_value); }