loglinesType * testcase_get_logmessages(gchar *logs) { int i, len; loglinesType *self; gchar **input_lines; gchar *logline; GSockAddr *addr = g_sockaddr_inet_new("10.10.10.10", 1010); LogMessage *msg; self = g_new(loglinesType, 1); self->logmessages = g_ptr_array_sized_new(10); self->num_of_logs = 0; input_lines = g_strsplit(logs, "\n", 0); for (i = 0; input_lines[i]; ++i) { logline = g_strdup_printf("Jul 29 06:25:41 vav zorp/inter_http[27940]: %s", input_lines[i]); len = strlen(logline); if (logline[len-1] == '\n') logline[len-1] = 0; msg = log_msg_new(logline, len, addr, &parse_options); g_ptr_array_add(self->logmessages, msg); ++(self->num_of_logs); g_free(logline); } msg_format_options_destroy(&parse_options); return self; }
void log_reader_options_destroy(LogReaderOptions *options) { log_source_options_destroy(&options->super); log_proto_server_options_destroy(&options->proto_options.super); msg_format_options_destroy(&options->parse_options); options->initialized = FALSE; }
void log_reader_options_destroy(LogReaderOptions *options) { log_source_options_destroy(&options->super); msg_format_options_destroy(&options->parse_options); if (options->text_encoding) { g_free(options->text_encoding); options->text_encoding = NULL; } }
/* * NOTE: options_init and options_destroy are a bit weird, because their * invocation is not completely symmetric: * * - init is called from driver init (e.g. affile_sd_init), * - destroy is called from driver free method (e.g. affile_sd_free, NOT affile_sd_deinit) * * The reason: * - when initializing the reloaded configuration fails for some reason, * we have to fall back to the old configuration, thus we cannot dump * the information stored in the Options structure. * * For the reasons above, init and destroy behave the following way: * * - init is idempotent, it can be called multiple times without leaking * memory, and without loss of information * - destroy is only called once, when the options are indeed to be destroyed * * As init allocates memory, it has to take care about freeing memory * allocated by the previous init call (or it has to reuse those). * */ void msg_format_options_init(MsgFormatOptions *options, GlobalConfig *cfg) { gchar *recv_time_zone, *format; TimeZoneInfo *recv_time_zone_info; MsgFormatHandler *format_handler; Plugin *p; recv_time_zone = options->recv_time_zone; options->recv_time_zone = NULL; recv_time_zone_info = options->recv_time_zone_info; options->recv_time_zone_info = NULL; format = options->format; options->format = NULL; format_handler = options->format_handler; options->format_handler = NULL; msg_format_options_destroy(options); options->format = format; options->format_handler = format_handler; options->recv_time_zone = recv_time_zone; options->recv_time_zone_info = recv_time_zone_info; if (cfg->bad_hostname_compiled) options->bad_hostname = &cfg->bad_hostname; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); if (!options->format) options->format = g_strdup("syslog"); p = plugin_find(cfg, LL_CONTEXT_FORMAT, options->format); if (p) options->format_handler = plugin_construct(p, cfg, LL_CONTEXT_FORMAT, options->format); }