static gboolean afamqp_worker_publish(AMQPDestDriver *self, LogMessage *msg) { gint pos = 0, ret; amqp_table_t table; amqp_basic_properties_t props; gboolean success = TRUE; SBGString *routing_key = sb_gstring_acquire(); SBGString *body = sb_gstring_acquire(); amqp_bytes_t body_bytes = amqp_cstring_bytes(""); gpointer user_data[] = { &self->entries, &pos, &self->max_entries }; value_pairs_foreach(self->vp, afamqp_vp_foreach, msg, self->seq_num, &self->template_options, user_data); table.num_entries = pos; table.entries = self->entries; props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG | AMQP_BASIC_HEADERS_FLAG; props.content_type = amqp_cstring_bytes("text/plain"); props.delivery_mode = self->persistent; props.headers = table; log_template_format(self->routing_key_template, msg, NULL, LTZ_LOCAL, self->seq_num, NULL, sb_gstring_string(routing_key)); if (self->body_template) { log_template_format(self->body_template, msg, NULL, LTZ_LOCAL, self->seq_num, NULL, sb_gstring_string(body)); body_bytes = amqp_cstring_bytes(sb_gstring_string(body)->str); } ret = amqp_basic_publish(self->conn, 1, amqp_cstring_bytes(self->exchange), amqp_cstring_bytes(sb_gstring_string(routing_key)->str), 0, 0, &props, body_bytes); sb_gstring_release(routing_key); sb_gstring_release(body); if (ret < 0) { msg_error("Network error while inserting into AMQP server", evt_tag_str("driver", self->super.super.super.id), evt_tag_int("time_reopen", self->super.time_reopen), NULL); success = FALSE; } while (--pos >= 0) { amqp_bytes_free(self->entries[pos].key); amqp_bytes_free(self->entries[pos].value.value.bytes); } return success; }
gchar * value_pairs_transform_set_apply(ValuePairsTransformSet *vpts, gchar *key) { if (g_pattern_match_string(vpts->pattern, key)) { GList *l; SBGString *sb; gchar *new_key; sb = sb_gstring_acquire (); g_string_assign(sb_gstring_string(sb), key); l = vpts->transforms; while (l) { value_pairs_transform_apply((ValuePairsTransform *)l->data, sb); l = l->next; } new_key = sb_gstring_string(sb)->str; g_string_steal(sb_gstring_string(sb)); sb_gstring_release (sb); return new_key; } return g_strdup(key); }
gboolean fop_cmp_eval(FilterExprNode *s, LogMessage **msgs, gint num_msg) { FilterCmp *self = (FilterCmp *) s; SBGString *left_buf = sb_gstring_acquire(); SBGString *right_buf = sb_gstring_acquire(); gboolean result = FALSE; gint cmp; log_template_format_with_context(self->left, msgs, num_msg, NULL, LTZ_LOCAL, 0, NULL, sb_gstring_string(left_buf)); log_template_format_with_context(self->right, msgs, num_msg, NULL, LTZ_LOCAL, 0, NULL, sb_gstring_string(right_buf)); if (self->cmp_op & FCMP_NUM) { gint l, r; l = atoi(sb_gstring_string(left_buf)->str); r = atoi(sb_gstring_string(right_buf)->str); if (l == r) cmp = 0; else if (l < r) cmp = -1; else cmp = 1; } else { cmp = strcmp(sb_gstring_string(left_buf)->str, sb_gstring_string(right_buf)->str); } if (cmp == 0) { result = self->cmp_op & FCMP_EQ; } else if (cmp < 0) { result = self->cmp_op & FCMP_LT || self->cmp_op == 0; } else { result = self->cmp_op & FCMP_GT || self->cmp_op == 0; } sb_gstring_release(left_buf); sb_gstring_release(right_buf); return result ^ s->comp; }
static void _add_nv_pair_int(LogTransportAuxData *aux, const gchar *name, gint value) { SBGString *sbbuf = sb_gstring_acquire(); GString *buf = sb_gstring_string(sbbuf); g_string_truncate(buf, 0); format_uint32_padded(buf, -1, 0, 10, value); log_transport_aux_data_add_nv_pair(aux, name, buf->str); sb_gstring_release(sbbuf); }
static gboolean geoip_parser_process(LogParser *s, LogMessage **pmsg, const LogPathOptions *path_options, const gchar *input, gsize input_len) { GeoIPParser *self = (GeoIPParser *) s; LogMessage *msg = log_msg_make_writable(pmsg, path_options); GeoIPRecord *record; SBGString *value; if (!self->dest.country_code && !self->dest.latitude && !self->dest.longitude) return TRUE; record = GeoIP_record_by_name(self->gi, input); if (!record) { const char *country; country = GeoIP_country_code_by_name(self->gi, input); if (country) log_msg_set_value_by_name(msg, self->dest.country_code, country, strlen(country)); return TRUE; } if (record->country_code) log_msg_set_value_by_name(msg, self->dest.country_code, record->country_code, strlen(record->country_code)); value = sb_gstring_acquire(); g_string_printf(sb_gstring_string(value), "%f", record->latitude); log_msg_set_value_by_name(msg, self->dest.latitude, sb_gstring_string(value)->str, sb_gstring_string(value)->len); g_string_printf(sb_gstring_string(value), "%f", record->longitude); log_msg_set_value_by_name(msg, self->dest.longitude, sb_gstring_string(value)->str, sb_gstring_string(value)->len); GeoIPRecord_delete(record); sb_gstring_release(value); return TRUE; }
static gboolean afstomp_worker_publish(STOMPDestDriver *self, LogMessage *msg) { gboolean success = TRUE; SBGString *body = NULL; stomp_frame frame; stomp_frame recv_frame; gchar seq_num[16]; if (!self->conn) { msg_error("STOMP server is not connected, not sending message!", NULL); return FALSE; } body = sb_gstring_acquire(); stomp_frame_init(&frame, "SEND", sizeof("SEND")); if (self->persistent) stomp_frame_add_header(&frame, "persistent", "true"); stomp_frame_add_header(&frame, "destination", self->destination); if (self->ack_needed) { g_snprintf(seq_num, sizeof(seq_num), "%i", self->super.seq_num); stomp_frame_add_header(&frame, "receipt", seq_num); }; value_pairs_foreach(self->vp, afstomp_vp_foreach, msg, self->super.seq_num, LTZ_SEND, &self->template_options, &frame); afstomp_set_frame_body(self, body, &frame, msg); if (!afstomp_send_frame(self, &frame)) { msg_error("Error while inserting into STOMP server", NULL); success = FALSE; } if (success && self->ack_needed) success = stomp_receive_frame(self->conn, &recv_frame); sb_gstring_release(body); return success; }
static void log_json_parser_process_single (struct json_object *jso, const gchar *prefix, const gchar *obj_key, LogMessage *msg) { SBGString *key, *value; gboolean parsed = FALSE; key = sb_gstring_acquire (); value = sb_gstring_acquire (); switch (json_object_get_type (jso)) { case json_type_boolean: parsed = TRUE; if (json_object_get_boolean (jso)) g_string_assign (sb_gstring_string (value), "true"); else g_string_assign (sb_gstring_string (value), "false"); break; case json_type_double: parsed = TRUE; g_string_printf (sb_gstring_string (value), "%f", json_object_get_double (jso)); break; case json_type_int: parsed = TRUE; g_string_printf (sb_gstring_string (value), "%i", json_object_get_int (jso)); break; case json_type_string: parsed = TRUE; g_string_assign (sb_gstring_string (value), json_object_get_string (jso)); break; case json_type_object: if (prefix) g_string_assign (sb_gstring_string (key), prefix); g_string_append (sb_gstring_string (key), obj_key); g_string_append_c (sb_gstring_string (key), '.'); log_json_parser_process_object (jso, sb_gstring_string (key)->str, msg); break; case json_type_array: { gint i, plen; g_string_assign (sb_gstring_string (key), obj_key); plen = sb_gstring_string (key)->len; for (i = 0; i < json_object_array_length (jso); i++) { g_string_truncate (sb_gstring_string (key), plen); g_string_append_printf (sb_gstring_string (key), "[%d]", i); log_json_parser_process_single (json_object_array_get_idx (jso, i), prefix, sb_gstring_string (key)->str, msg); } break; } case json_type_null: break; default: msg_error ("JSON parser encountered an unknown type, skipping", evt_tag_str ("key", obj_key), NULL); break; } if (parsed) { if (prefix) { g_string_assign (sb_gstring_string (key), prefix); g_string_append (sb_gstring_string (key), obj_key); log_msg_set_value (msg, log_msg_get_value_handle (sb_gstring_string (key)->str), sb_gstring_string (value)->str, sb_gstring_string (value)->len); } else log_msg_set_value (msg, log_msg_get_value_handle (obj_key), sb_gstring_string (value)->str, sb_gstring_string (value)->len); } sb_gstring_release (key); sb_gstring_release (value); }