Exemple #1
0
static int load_config(void)
{
	struct cw_variable *var;
	struct cw_config *cfg;
	char *cat;

	res_snmp_enabled = 0;
	res_snmp_agentx_subagent = 1;
	cfg = cw_config_load("res_snmp.conf");
	if (!cfg) {
		cw_log(LOG_WARNING, "Could not load res_snmp.conf\n");
		return 0;
	}
	cat = cw_category_browse(cfg, NULL);
	while (cat) {
		var = cw_variable_browse(cfg, cat);

		if (strcasecmp(cat, "general") == 0) {
			while (var) {
				if (strcasecmp(var->name, "subagent") == 0) {
					if (cw_true(var->value))
						res_snmp_agentx_subagent = 1;
					else if (cw_false(var->value))
						res_snmp_agentx_subagent = 0;
					else {
						cw_log(LOG_ERROR, "Value '%s' does not evaluate to true or false.\n", var->value);
						cw_config_destroy(cfg);
						return 1;
					}
				} else if (strcasecmp(var->name, "enabled") == 0) {
					res_snmp_enabled = cw_true(var->value);
				} else {
					cw_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
					cw_config_destroy(cfg);
					return 1;
				}
				var = var->next;
			}
		} else {
			cw_log(LOG_ERROR, "Unrecognized category '%s'\n", cat);
			cw_config_destroy(cfg);
			return 1;
		}

		cat = cw_category_browse(cfg, cat);
	}
	cw_config_destroy(cfg);
	return 1;
}
Exemple #2
0
static void cw_db_load_config(void)
{
#ifdef HAVE_MEMCACHE
    struct cw_config *cfg;
    char *s;
    int disabled = 0;

    db_server_host = NULL;
    db_server_port = NULL;
    db_cache_lifetime = 0;

    if ((cfg = cw_config_load("db-memcached.conf")))
    {

        if ((s = cw_variable_retrieve(cfg, "memcache", "enabled")))
        {
            if (cw_false(s)) {
                cw_log(LOG_DEBUG,"Memcache server is disabled by configuration.\n");
                disabled = 1;
                return;
            }
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "server_host")))
        {
            cw_log(LOG_DEBUG,"Memcache server host is %s\n",s);
            db_server_host = strdup(s);
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "server_port")))
        {
            cw_log(LOG_DEBUG,"Memcache server port is %s\n",s);
            db_server_port = strdup(s);
        }

        if ((s = cw_variable_retrieve(cfg, "memcache", "cache_lifetime")))
        {
            cw_log(LOG_DEBUG,"Memcache server cache lifetime is %s\n",s);
            db_cache_lifetime = atoi(s);
        }

        cw_config_destroy(cfg);
    }
#endif
}