Example #1
0
File: hub.c Project: imobilis/uhub
void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
{
	char* tmp;
	char* server = adc_msg_escape(PRODUCT_STRING); /* FIXME: OOM */

	hub->acl = acl;
	hub->command_info = adc_msg_construct(ADC_CMD_IINF, 15);
	if (hub->command_info)
	{
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_CLIENT_TYPE, ADC_CLIENT_TYPE_HUB);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_USER_AGENT_PRODUCT, PRODUCT);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_USER_AGENT_VERSION, GIT_VERSION);

		tmp = adc_msg_escape(hub->config->hub_name);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_NICK, tmp);
		hub_free(tmp);

		tmp = adc_msg_escape(hub->config->hub_description);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_DESCRIPTION, tmp);
		hub_free(tmp);
	}

	hub->command_support = adc_msg_construct(ADC_CMD_ISUP, 6 + strlen(ADC_PROTO_SUPPORT));
	if (hub->command_support)
	{
		adc_msg_add_argument(hub->command_support, ADC_PROTO_SUPPORT);
	}

	hub->command_banner = adc_msg_construct(ADC_CMD_ISTA, 100 + strlen(server));
	if (hub->command_banner)
	{
		if (hub->config->show_banner_sys_info)
			tmp = adc_msg_escape("Powered by " PRODUCT_STRING " on " OPSYS "/" CPUINFO);
		else
			tmp = adc_msg_escape("Powered by " PRODUCT_STRING);
		adc_msg_add_argument(hub->command_banner, "000");
		adc_msg_add_argument(hub->command_banner, tmp);
		hub_free(tmp);
	}

	if (hub_plugins_load(hub) < 0)
	{
		LOG_FATAL("Unable to load plugins.");
		hub->status = hub_status_shutdown;
	}
	else

	hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled);
	hub_free(server);
}
Example #2
0
File: hub.c Project: q3k/uhub
void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
{
	int fd, ret;
	char buf[MAX_RECV_BUF];
	char* tmp;
	char* server = adc_msg_escape(PRODUCT_STRING); /* FIXME: OOM */

	hub->acl = acl;
	hub->command_info = adc_msg_construct(ADC_CMD_IINF, 15);
	if (hub->command_info)
	{
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_CLIENT_TYPE, ADC_CLIENT_TYPE_HUB);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_USER_AGENT, server);

		tmp = adc_msg_escape(hub->config->hub_name);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_NICK, tmp);
		hub_free(tmp);

		tmp = adc_msg_escape(hub->config->hub_description);
		adc_msg_add_named_argument(hub->command_info, ADC_INF_FLAG_DESCRIPTION, tmp);
		hub_free(tmp);
	}

	/* (Re-)read the message of the day */
	hub->command_motd = 0;
	fd = (hub->config->file_motd && *hub->config->file_motd) ? open(hub->config->file_motd, 0) : -1;
	if (fd != -1)
	{
		ret = read(fd, buf, MAX_RECV_BUF);
		if (ret > 0)
		{
			buf[ret] = 0;
			tmp = adc_msg_escape(buf);
			hub->command_motd = adc_msg_construct(ADC_CMD_IMSG, 6 + strlen(tmp));
			adc_msg_add_argument(hub->command_motd, tmp);
			hub_free(tmp);
		}
		close(fd);
	}

	hub->command_rules = 0;
	fd = (hub->config->file_rules && *hub->config->file_rules) ? open(hub->config->file_rules, 0) : -1;
	if (fd != -1)
	{
		ret = read(fd, buf, MAX_RECV_BUF);
		if (ret > 0)
		{
			buf[ret] = 0;
			tmp = adc_msg_escape(buf);
			hub->command_rules = adc_msg_construct(ADC_CMD_IMSG, 6 + strlen(tmp));
			adc_msg_add_argument(hub->command_rules, tmp);
			hub_free(tmp);
		}
		close(fd);
	}

	hub->command_support = adc_msg_construct(ADC_CMD_ISUP, 6 + strlen(ADC_PROTO_SUPPORT));
	if (hub->command_support)
	{
		adc_msg_add_argument(hub->command_support, ADC_PROTO_SUPPORT);
	}

	hub->command_banner = adc_msg_construct(ADC_CMD_ISTA, 100 + strlen(server));
	if (hub->command_banner)
	{
		if (hub->config->show_banner_sys_info)
			tmp = adc_msg_escape("Powered by " PRODUCT_STRING " on " OPSYS "/" CPUINFO);
		else
			tmp = adc_msg_escape("Powered by " PRODUCT_STRING);
		adc_msg_add_argument(hub->command_banner, "000");
		adc_msg_add_argument(hub->command_banner, tmp);
		hub_free(tmp);
	}

#ifdef PLUGIN_SUPPORT
	hub_plugins_load(hub);
#endif

	hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled);
	hub_free(server);
}