Exemplo n.º 1
0
struct conscience_srvtype_s *
conscience_srvtype_create(struct conscience_s *conscience, const char *type)
{
	struct conscience_srvtype_s *srvtype = g_malloc0(sizeof(struct conscience_srvtype_s));

	/*sets a default expression that always fits*/
	if (!conscience_srvtype_set_type_expression(srvtype, NULL, "100")) {
		ERROR("Failed to force the score to 100");
		conscience_srvtype_destroy(srvtype);
		return NULL;
	}

	/*allocate the hashtables */
	srvtype->services_ht = g_hash_table_new_full(hash_service_id,
			equal_service_id, NULL, NULL);
	srvtype->config_ht = g_hash_table_new_full(g_str_hash,
			g_str_equal, g_free, destroy_gba);
	if (!srvtype->config_ht || !srvtype->services_ht) {
		ERROR("HT allocation failure");
		conscience_srvtype_destroy(srvtype);
		abort();
		return NULL;
	}

	if (type)
		g_strlcpy(srvtype->type_name, type, sizeof(srvtype->type_name));
	srvtype->alert_frequency_limit = 0;
	srvtype->score_variation_bound = 0;
	srvtype->conscience = conscience;
	srvtype->services_ring.next = srvtype->services_ring.prev = &(srvtype->services_ring);
	return srvtype;
}
Exemplo n.º 2
0
void
conscience_destroy(struct conscience_s *conscience)
{
	if (!conscience)
		return;

	g_static_rw_lock_free(&(conscience->rwlock_srv));

	if (conscience->srvtypes)
		g_hash_table_destroy(conscience->srvtypes);

	if (conscience->default_srvtype)
		conscience_srvtype_destroy(conscience->default_srvtype);

	namespace_info_clear(&conscience->ns_info);

	memset(conscience, 0x00, sizeof(struct conscience_s));
	g_free(conscience);
}