static switch_status_t do_config(switch_bool_t reload)
{
	if (switch_xml_config_parse_module_settings("cidlookup.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
		return SWITCH_STATUS_GENERR;
	}

	return SWITCH_STATUS_SUCCESS;
}
Exemple #2
0
static switch_status_t load_config(switch_memory_pool_t *pool)
{
	switch_status_t status = SWITCH_STATUS_SUCCESS;

	if (switch_xml_config_parse_module_settings("cdr_mongodb.conf", SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {
		return SWITCH_STATUS_FALSE;
	}

	return status;
}
Exemple #3
0
static switch_status_t do_config(switch_bool_t reload)
{
	memset(&globals, 0, sizeof(globals));

	if (switch_xml_config_parse_module_settings("amd.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
		return SWITCH_STATUS_FALSE;
	}

	return SWITCH_STATUS_SUCCESS;
}
static switch_status_t load_config(switch_memory_pool_t *pool)
{
    switch_status_t status = SWITCH_STATUS_SUCCESS;
    char *cf = "cdr_pg_csv.conf", *ptr;
    switch_xml_t cfg, xml, schema, field;
    const char *attr;
    int num_fields = 0;
    switch_size_t len = 0;
    cdr_field_t *cdr_field;

    if (globals.db_online) {
        PQfinish(globals.db_connection);
        switch_mutex_destroy(globals.db_mutex);
        globals.db_online = 0;
    }

    memset(&globals, 0, sizeof(globals));
    switch_core_hash_init(&globals.fd_hash, pool);
    switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_NESTED, pool);

    globals.pool = pool;

    if (switch_xml_config_parse_module_settings(cf, SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {
        return SWITCH_STATUS_FALSE;
    }

    if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
        if ((schema = switch_xml_child(cfg, "schema"))) {
            /* Count fields in schema so we can calculate required buffer size */
            for (field = switch_xml_child(schema, "field"); field; field = field->next) {
                if (switch_xml_attr(field, "var")) {
                    num_fields++;
                }
            }

            globals.db_schema = switch_core_alloc(pool, (num_fields + 1) * sizeof(cdr_field_t));
            cdr_field = globals.db_schema->fields;

            for (field = switch_xml_child(schema, "field"); field; field = field->next) {
                if ((attr = switch_xml_attr(field, "var"))) {
                    cdr_field->var_name = switch_core_strdup(pool, attr);

                    /* Assume SQL column name is the same as FreeSWITCH channel var name, unless specified otherwise */
                    if ((attr = switch_xml_attr(field, "column"))) {
                        cdr_field->col_name = switch_core_strdup(pool, attr);
                    } else {
                        cdr_field->col_name = switch_core_strdup(pool, cdr_field->var_name);
                    }

                    /* Assume all fields should be quoted (treated as strings), unless specified otherwise */
                    if ((attr = switch_xml_attr(field, "quote")) && !strncmp(attr, "false", 5)) {
                        cdr_field->quote = SWITCH_FALSE;
                    } else {
                        cdr_field->quote = SWITCH_TRUE;
                    }

                    /* Assume all fields allow SQL nulls, unless specified otherwise */
                    if ((attr = switch_xml_attr(field, "not-null")) && !strncmp(attr, "true", 4)) {
                        cdr_field->not_null = SWITCH_TRUE;
                    } else {
                        cdr_field->not_null = SWITCH_FALSE;
                    }

                    len += strlen(cdr_field->col_name) + 1;
                    cdr_field++;
                }
            }
            cdr_field->var_name = 0;

            globals.db_schema->columns = switch_core_alloc(pool, len);
            ptr = globals.db_schema->columns;
            for (cdr_field = globals.db_schema->fields; cdr_field->col_name; cdr_field++) {
                len = strlen(cdr_field->col_name);
                memcpy(ptr, cdr_field->col_name, len);
                ptr += len;
                *ptr = ',';
                ptr++;
            }
            *--ptr = '\0';
        }

        switch_xml_free(xml);
    }

    return status;
}
Exemple #5
0
static switch_status_t do_config()
{
	switch_cache_db_handle_t *dbh = NULL;
	switch_status_t status = SWITCH_STATUS_SUCCESS;
	char *sql = NULL;

	limit_config_dsn.pool = globals.pool;

	if (switch_xml_config_parse_module_settings("db.conf", SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No config file found, defaulting to sqlite\n");
	}

	if (globals.odbc_dsn) {
		if ((globals.odbc_user = strchr(globals.odbc_dsn, ':'))) {
			*globals.odbc_user++ = '\0';
			if ((globals.odbc_pass = strchr(globals.odbc_user, ':'))) {
				*globals.odbc_pass++ = '\0';
			}
		}

		if (!(dbh = limit_get_db_handle())) {
			globals.odbc_dsn = globals.odbc_user = globals.odbc_pass;
		}
	}


	if (zstr(globals.odbc_dsn)) {
		globals.dbname = "call_limit";
		dbh = limit_get_db_handle();
	}


	if (dbh) {
		int x = 0;
		char *indexes[] = {
			"create index ld_hostname on limit_data (hostname)",
			"create index ld_uuid on limit_data (uuid)",
			"create index ld_realm on limit_data (realm)",
			"create index ld_id on limit_data (id)",
			"create index dd_realm on db_data (realm)",
			"create index dd_data_key on db_data (data_key)",
			"create index gd_groupname on group_data (groupname)",
			"create index gd_url on group_data (url)",
			NULL
		};



		switch_cache_db_test_reactive(dbh, "select * from limit_data", NULL, limit_sql);
		switch_cache_db_test_reactive(dbh, "select * from db_data", NULL, db_sql);
		switch_cache_db_test_reactive(dbh, "select * from group_data", NULL, group_sql);

		for (x = 0; indexes[x]; x++) {
			switch_cache_db_execute_sql(dbh, indexes[x], NULL);
		}

		switch_cache_db_release_db_handle(&dbh);

		sql = switch_mprintf("delete from limit_data where hostname='%q';", globals.hostname);
		limit_execute_sql(sql);
		switch_safe_free(sql);
	}

	return status;
}