Exemple #1
0
static int load_module(void)
{
	struct ast_config *cfg;
	int res;
	const char *tmp;

	if ((cfg = ast_config_load(cdr_config))) {
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD);
		if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg")))
			ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
		ast_config_destroy(cfg);
	} else 
		return AST_MODULE_LOAD_DECLINE;
	
	/* start logging */
	rc_openlog("asterisk");

	/* read radiusclient-ng config file */
	if (!(rh = rc_read_config(radiuscfg))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
		return AST_MODULE_LOAD_DECLINE;
	}

	/* read radiusclient-ng dictionaries */
	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
		return AST_MODULE_LOAD_DECLINE;
	}
	
	res = ast_cdr_register(name, desc, radius_log);
	return AST_MODULE_LOAD_SUCCESS;
}
Exemple #2
0
static int load_module(void) {
	if (ast_cdr_register(name, "Asterisk CDR Beanstalkd Backend", beanstalk_put)) {
		return AST_MODULE_LOAD_DECLINE;
	}

	if (load_config(0)) {
		ast_cdr_unregister(name);
		return AST_MODULE_LOAD_DECLINE;
	}

	return AST_MODULE_LOAD_SUCCESS;
}
int load_module(void)
{
	int res;

	res = ast_cdr_register(name, desc, csv_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");
		if (mf)
			fclose(mf);
	}
	return res;
}
Exemple #4
0
static int load_module(void)
{
	int res = 0;

	if (!load_config(0)) {
		res = ast_cdr_register(name, ast_module_info->description, syslog_log);
		if (res)
			ast_log(LOG_ERROR, "Unable to register syslog CDR handling\n");
		return res;
	} else 
		return AST_MODULE_LOAD_DECLINE;
}
static int load_module(void *mod)
{
	int res = 0;

	if (!load_config(0)) {
		res = ast_cdr_register(name, desc, custom_log);
		if (res)
			ast_log(LOG_ERROR, "Unable to register custom CDR handling\n");
		if (mf)
			fclose(mf);
	}
	return res;
}
int load_module(void)
{
	int res = 0;
	do_reload = 1;
	load_config(1);
	do_reload = 0;

	ast_config_engine_register(&sqlite_engine);
	ast_verbose(VERBOSE_PREFIX_2 "SQLite Config Handler Registered.\n");


	if (has_cdr) {
		ast_verbose(VERBOSE_PREFIX_2 "Loading SQLite CDR\n");
		res = ast_cdr_register(cdr_name, "RES SQLite CDR", sqlite_log);
	}
	else 
		ast_verbose(VERBOSE_PREFIX_2 "SQLite CDR Disabled\n");



	ast_register_application(app, sqlite_execapp, synopsis, tdesc);


	if (has_switch) {
		if (ast_register_switch(&sqlite_switch))
			ast_log(LOG_ERROR, "Unable to register SQLite Switch\n");
		else {
			sqlite3HashInit(&extens,SQLITE_HASH_STRING,COPY_KEYS);
			ast_verbose(VERBOSE_PREFIX_2 "Registered SQLite Switch\n");
		}
	}
	else 
		ast_verbose(VERBOSE_PREFIX_2 "Sqlite Switch Disabled\n");

	if (has_cli) {
		ast_verbose(VERBOSE_PREFIX_2 "Activating SQLite CLI Command Set.\n");
		ast_cli_register(&cli_sqlite1); 
		ast_cli_register(&cli_sqlite2);	 
		ast_cli_register(&cli_sqlite3);	 
		ast_cli_register(&cli_sqlite4);	 
		ast_cli_register(&cli_sqlite5);	 
		ast_cli_register(&cli_sqlite6);
		ast_cli_register(&cli_sqlite7);
		ast_cli_register(&cli_sqlite8);
		ast_cli_register(&cli_sqlite9);
	}
	else 
		ast_verbose(VERBOSE_PREFIX_2 "SQLite CLI Command Set Not Configured.\n");

	return res;
}
Exemple #7
0
static int load_module(void)
{
	struct ast_config *cfg;
	struct ast_flags config_flags = { 0 };
	const char *tmp;

	if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID);
		ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD);
		if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg")))
			ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
		ast_config_destroy(cfg);
	} else
		return AST_MODULE_LOAD_DECLINE;

	/*
	 * start logging
	 *
	 * NOTE: Yes this causes a slight memory leak if the module is
	 * unloaded.  However, it is better than a crash if cdr_radius
	 * and cel_radius are both loaded.
	 */
	tmp = ast_strdup("asterisk");
	if (tmp) {
		rc_openlog((char *) tmp);
	}

	/* read radiusclient-ng config file */
	if (!(rh = rc_read_config(radiuscfg))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
		return AST_MODULE_LOAD_DECLINE;
	}

	/* read radiusclient-ng dictionaries */
	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
		ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	}

	if (ast_cdr_register(name, desc, radius_log)) {
		rc_destroy(rh);
		rh = NULL;
		return AST_MODULE_LOAD_DECLINE;
	} else {
		return AST_MODULE_LOAD_SUCCESS;
	}
}
Exemple #8
0
int load_module(void)
{
	int res;

	/* Configuration file */
	loadconfigurationfile();
	
	res = ast_cdr_register(name, desc, manager_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
	}
	
	return res;
}
Exemple #9
0
static int load_module(void)
{
	int res;

	if(!load_config(0))
		return AST_MODULE_LOAD_DECLINE;

	if ((res = ast_cdr_register(name, ast_module_info->description, csv_log))) {
		ast_log(LOG_ERROR, "Unable to register CSV CDR handling\n");
	} else {
		loaded = 1;
	}
	return res;
}
Exemple #10
0
static int load_module(void)
{
	int res;

	/* Configuration file */
	if (!loadconfigurationfile())
		return AST_MODULE_LOAD_DECLINE;
	
	res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
	}
	
	return res;
}
Exemple #11
0
static int load_module(void)
{
	char *zErr;
	char fn[PATH_MAX];
	int res;

	/* is the database there? */
	snprintf(fn, sizeof(fn), "%s/cdr.db", ast_config_AST_LOG_DIR);
	db = sqlite_open(fn, 0660, &zErr);
	if (!db) {
		ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
		free(zErr);
		return -1;
	}

	/* is the table there? */
	res = sqlite_exec(db, "SELECT COUNT(id) FROM cdr;", NULL, NULL, NULL);
	if (res) {
		res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
		if (res) {
			ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr);
			free(zErr);
			goto err;
		}
		/*res = sqlite_exec(db, sql_create_trigger, NULL, NULL, &zErr);
		if (res) {
			ast_log(LOG_ERROR, "cdr_sqlite: Unable to create maxentries trigger: %s\n", zErr);
			free(zErr);
			goto err;
		}*/

		/* TODO: here we should probably create an index */
	}
	
	res = ast_cdr_register(name, ast_module_info->description, sqlite_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register SQLite CDR handling\n");
		return -1;
	}
	return 0;

err:
	if (db)
		sqlite_close(db);
	return -1;
}
Exemple #12
0
static int load_module(void)
{
	char *zErr;
	char fn[PATH_MAX];
	int res;

	ast_log(LOG_NOTICE, "This module has been marked deprecated in favor of "
		"using cdr_sqlite3_custom.\n");

	/* is the database there? */
	snprintf(fn, sizeof(fn), "%s/cdr.db", ast_config_AST_LOG_DIR);
	db = sqlite_open(fn, AST_FILE_MODE, &zErr);
	if (!db) {
		ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr);
		ast_free(zErr);
		return AST_MODULE_LOAD_DECLINE;
	}

	/* is the table there? */
	res = sqlite_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL);
	if (res) {
		res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr);
		if (res) {
			ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr);
			ast_free(zErr);
			goto err;
		}

		/* TODO: here we should probably create an index */
	}

	res = ast_cdr_register(name, ast_module_info->description, sqlite_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register SQLite CDR handling\n");
		return AST_MODULE_LOAD_DECLINE;
	}
	return AST_MODULE_LOAD_SUCCESS;

err:
	if (db)
		sqlite_close(db);
	return AST_MODULE_LOAD_DECLINE;
}
Exemple #13
0
static int process_my_load_module(struct ast_config *cfg)
{
	struct ast_variable *var;
        char *pgerror;
	const char *tmp;

	if (!(var = ast_variable_browse(cfg, "global")))
		return 0;

	if (!(tmp = ast_variable_retrieve(cfg,"global","hostname"))) {
		ast_log(LOG_WARNING,"PostgreSQL server hostname not specified.  Assuming unix socket connection\n");
		tmp = "";	/* connect via UNIX-socket by default */
	}
	
	if (!(pghostname = ast_strdup(tmp)))
		return -1;

	if (!(tmp = ast_variable_retrieve(cfg, "global", "dbname"))) {
		ast_log(LOG_WARNING,"PostgreSQL database not specified.  Assuming asterisk\n");
		tmp = "asteriskcdrdb";
	}

	if (!(pgdbname = ast_strdup(tmp)))
		return -1;

	if (!(tmp = ast_variable_retrieve(cfg, "global", "user"))) {
		ast_log(LOG_WARNING,"PostgreSQL database user not specified.  Assuming asterisk\n");
		tmp = "asterisk";
	}

	if (!(pgdbuser = ast_strdup(tmp)))
		return -1;

	if (!(tmp = ast_variable_retrieve(cfg, "global", "password"))) {
		ast_log(LOG_WARNING,"PostgreSQL database password not specified.  Assuming blank\n");
		tmp = "";
	}

	if (!(pgpassword = ast_strdup(tmp)))
		return -1;

	if (!(tmp = ast_variable_retrieve(cfg,"global","port"))) {
		ast_log(LOG_WARNING,"PostgreSQL database port not specified.  Using default 5432.\n");
		tmp = "5432";
	}

	if (!(pgdbport = ast_strdup(tmp)))
		return -1;

	if (!(tmp = ast_variable_retrieve(cfg, "global", "table"))) {
		ast_log(LOG_WARNING,"CDR table not specified.  Assuming cdr\n");
		tmp = "cdr";
	}

	if (!(table = ast_strdup(tmp)))
		return -1;

	if (option_debug) {
	    	if (ast_strlen_zero(pghostname))
			ast_log(LOG_DEBUG, "cdr_pgsql: using default unix socket\n");
		else
			ast_log(LOG_DEBUG, "cdr_pgsql: got hostname of %s\n", pghostname);
		ast_log(LOG_DEBUG, "cdr_pgsql: got port of %s\n", pgdbport);
		ast_log(LOG_DEBUG, "cdr_pgsql: got user of %s\n", pgdbuser);
		ast_log(LOG_DEBUG, "cdr_pgsql: got dbname of %s\n", pgdbname);
		ast_log(LOG_DEBUG, "cdr_pgsql: got password of %s\n", pgpassword);
		ast_log(LOG_DEBUG, "cdr_pgsql: got sql table name of %s\n", table);
	}
	
	conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
	if (PQstatus(conn) != CONNECTION_BAD) {
		if (option_debug)
			ast_log(LOG_DEBUG, "Successfully connected to PostgreSQL database.\n");
		connected = 1;
	} else {
                pgerror = PQerrorMessage(conn);
		ast_log(LOG_ERROR, "cdr_pgsql: Unable to connect to database server %s.  CALLS WILL NOT BE LOGGED!!\n", pghostname);
                ast_log(LOG_ERROR, "cdr_pgsql: Reason: %s\n", pgerror);
		connected = 0;
	}

	return ast_cdr_register(name, ast_module_info->description, pgsql_log);
}
Exemple #14
0
static int _load_module(int reload)
{
    int res;
	struct ast_config *cfg;
	struct ast_variable *var;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

	mongo conn[1];
	bson b[1];

	ast_debug(1, "Starting mongodb module load.\n");
	ast_debug(1, "Loading mongodb Config.\n");

	if (!(cfg = ast_config_load(config, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_WARNING, "Unable to load config for mongodb CDR's: %s\n", config);
		return AST_MODULE_LOAD_SUCCESS;
	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return AST_MODULE_LOAD_SUCCESS;
	}


	if (reload) {
		_unload_module(1);
	}

	ast_debug(1, "Browsing mongodb Global.\n");
	var = ast_variable_browse(cfg, "global");
	if (!var) {
		return AST_MODULE_LOAD_SUCCESS;
	}

	res = 0;

	res |= load_config_string(cfg, "global", "hostname", &hostname, "localhost");
	res |= load_config_string(cfg, "global", "dbname", &dbname, "astriskcdrdb");
	res |= load_config_string(cfg, "global", "collection", &dbcollection, "cdr");
	res |= load_config_number(cfg, "global", "port", &dbport, 27017);
	res |= load_config_string(cfg, "global", "username", &dbuser, "");
	res |= load_config_string(cfg, "global", "password", &password, "");

	if (res < 0) {
		return AST_MODULE_LOAD_FAILURE;
	}

	ast_debug(1, "Got hostname of %s\n", ast_str_buffer(hostname));
	ast_debug(1, "Got port of %d\n", dbport);
	ast_debug(1, "Got dbname of %s\n", ast_str_buffer(dbname));
	ast_debug(1, "Got dbcollection of %s\n", ast_str_buffer(dbcollection));
	ast_debug(1, "Got user of %s\n", ast_str_buffer(dbuser));
	ast_debug(1, "Got password of %s\n", ast_str_buffer(password));
	
	
	dbnamespace = ast_str_create(255);
	ast_str_set(&dbnamespace, 0, "%s.%s", ast_str_buffer(dbname), ast_str_buffer(dbcollection));

	if (mongo_connect(&conn , ast_str_buffer(hostname), dbport) != MONGO_OK) {
		ast_log(LOG_ERROR, "Method: _load_module, MongoDB failed to connect to %s:%d!\n", ast_str_buffer(hostname), dbport);
		res = -1;
	} else {
		if (ast_str_strlen(dbuser) != 0 && (mongo_cmd_authenticate(&conn, ast_str_buffer(dbname), ast_str_buffer(dbuser), ast_str_buffer(password)) != MONGO_OK)) {
			ast_log(LOG_ERROR, "Method: _load_module, MongoDB failed to authenticate to do %s with username %s!\n", ast_str_buffer(dbname), ast_str_buffer(dbuser));
			res = -1;
		} else {
			connected = 1;
		}
		
		mongo_destroy(&conn);
	}

	ast_config_destroy(cfg);

	res = ast_cdr_register(name, desc, mongodb_log);
	if (res) {
		ast_log(LOG_ERROR, "Unable to register MongoDB CDR handling\n");
	} else {
		res = ast_cli_register_multiple(cdr_mongodb_status_cli, sizeof(cdr_mongodb_status_cli) / sizeof(struct ast_cli_entry));
	}

	return res;
}
static int tds_load_module(void)
{
	int res = 0;
	struct ast_config *cfg;
	struct ast_variable *var;
	char *ptr = NULL;
#ifdef FREETDS_PRE_0_62
	TDS_INT result_type;
#endif

	cfg = ast_config_load(config);
	if (!cfg) {
		ast_log(LOG_NOTICE, "Unable to load config for MSSQL CDR's: %s\n", config);
		return 0;
	}

	var = ast_variable_browse(cfg, "global");
	if (!var) /* nothing configured */
		return 0;

	ptr = ast_variable_retrieve(cfg, "global", "hostname");
	if (ptr)
		hostname = strdup(ptr);
	else
		ast_log(LOG_ERROR,"Database server hostname not specified.\n");

	ptr = ast_variable_retrieve(cfg, "global", "dbname");
	if (ptr)
		dbname = strdup(ptr);
	else
		ast_log(LOG_ERROR,"Database dbname not specified.\n");

	ptr = ast_variable_retrieve(cfg, "global", "user");
	if (ptr)
		dbuser = strdup(ptr);
	else
		ast_log(LOG_ERROR,"Database dbuser not specified.\n");

	ptr = ast_variable_retrieve(cfg, "global", "password");
	if (ptr)
		password = strdup(ptr);
	else
		ast_log(LOG_ERROR,"Database password not specified.\n");

	ptr = ast_variable_retrieve(cfg, "global", "charset");
	if (ptr)
		charset = strdup(ptr);
	else
		charset = strdup("iso_1");

	ptr = ast_variable_retrieve(cfg, "global", "language");
	if (ptr)
		language = strdup(ptr);
	else
		language = strdup("us_english");

	ast_config_destroy(cfg);

	mssql_connect();

	/* Register MSSQL CDR handler */
	res = ast_cdr_register(name, desc, tds_log);
	if (res)
	{
		ast_log(LOG_ERROR, "Unable to register MSSQL CDR handling\n");
	}

	return res;
}
Exemple #16
0
static int load_config(int reload)
{
	char *cat = NULL;
	struct ast_config *cfg;
	struct ast_variable *v;
	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
	int newenablecdr = 0;

	cfg = ast_config_load(CONF_FILE, config_flags);
	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
		return 0;
	}

	if (cfg == CONFIG_STATUS_FILEINVALID) {
		ast_log(LOG_ERROR, "Config file '%s' could not be parsed\n", CONF_FILE);
		return -1;
	}

	if (!cfg) {
		/* Standard configuration */
		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
		if (enablecdr)
			ast_cdr_unregister(name);
		enablecdr = 0;
		return -1;
	}

	if (reload) {
		ast_rwlock_wrlock(&customfields_lock);
	}

	if (reload && customfields) {
		ast_free(customfields);
		customfields = NULL;
	}

	while ( (cat = ast_category_browse(cfg, cat)) ) {
		if (!strcasecmp(cat, "general")) {
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (!strcasecmp(v->name, "enabled"))
					newenablecdr = ast_true(v->value);

				v = v->next;
			}
		} else if (!strcasecmp(cat, "mappings")) {
			customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
			v = ast_variable_browse(cfg, cat);
			while (v) {
				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) {
						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
					} else {
						ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
						break;
					}

				}
				v = v->next;
			}
		}
	}

	if (reload) {
		ast_rwlock_unlock(&customfields_lock);
	}

	ast_config_destroy(cfg);

	if (enablecdr && !newenablecdr)
		ast_cdr_unregister(name);
	else if (!enablecdr && newenablecdr)
		ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
	enablecdr = newenablecdr;

	return 0;
}
Exemple #17
0
static int odbc_load_module(void)
{
	int res = 0;
	struct ast_config *cfg;
	struct ast_variable *var;
	const char *tmp;

	ast_mutex_lock(&odbc_lock);

	cfg = ast_config_load(config);
	if (!cfg) {
		ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config);
		res = AST_MODULE_LOAD_DECLINE;
		goto out;
	}
	
	var = ast_variable_browse(cfg, "global");
	if (!var) {
		/* nothing configured */
		goto out;
	}

	tmp = ast_variable_retrieve(cfg,"global","dsn");
	if (tmp == NULL) {
		ast_log(LOG_WARNING,"cdr_odbc: dsn not specified.  Assuming asteriskdb\n");
		tmp = "asteriskdb";
	}
	dsn = strdup(tmp);
	if (dsn == NULL) {
		ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
		res = -1;
		goto out;
	}

	tmp = ast_variable_retrieve(cfg,"global","dispositionstring");
	if (tmp) {
		dispositionstring = ast_true(tmp);
	} else {
		dispositionstring = 0;
	}
		
	tmp = ast_variable_retrieve(cfg,"global","username");
	if (tmp) {
		username = strdup(tmp);
		if (username == NULL) {
			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
			res = -1;
			goto out;
		}
	}

	tmp = ast_variable_retrieve(cfg,"global","password");
	if (tmp) {
		password = strdup(tmp);
		if (password == NULL) {
			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
			res = -1;
			goto out;
		}
	}

	tmp = ast_variable_retrieve(cfg,"global","loguniqueid");
	if (tmp) {
		loguniqueid = ast_true(tmp);
		if (loguniqueid) {
			ast_log(LOG_DEBUG,"cdr_odbc: Logging uniqueid\n");
		} else {
			ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
		}
	} else {
		ast_log(LOG_DEBUG,"cdr_odbc: Not logging uniqueid\n");
		loguniqueid = 0;
	}

	tmp = ast_variable_retrieve(cfg,"global","usegmtime");
	if (tmp) {
		usegmtime = ast_true(tmp);
		if (usegmtime) {
			ast_log(LOG_DEBUG,"cdr_odbc: Logging in GMT\n");
		} else {
			ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
		}
	} else {
		ast_log(LOG_DEBUG,"cdr_odbc: Not logging in GMT\n");
		usegmtime = 0;
	}

	tmp = ast_variable_retrieve(cfg,"global","table");
	if (tmp == NULL) {
		ast_log(LOG_WARNING,"cdr_odbc: table not specified.  Assuming cdr\n");
		tmp = "cdr";
	}
	table = strdup(tmp);
	if (table == NULL) {
		ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
		res = -1;
		goto out;
	}

	if (option_verbose > 2) {
		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn);
		if (username)
		{
			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username);
			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n");
		}
		else
			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: retreiving username and password from odbc config\n");
		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: table is %s\n",table);
	}
	
	res = odbc_init();
	if (res < 0) {
		ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
		if (option_verbose > 2) {
			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
		}
	}
	res = ast_cdr_register(name, ast_module_info->description, odbc_log);
	if (res) {
		ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n");
	}
out:
	if (cfg)
		ast_config_destroy(cfg);
	ast_mutex_unlock(&odbc_lock);
	return res;
}
Exemple #18
0
static int odbc_load_module(int reload)
{
    int res = 0;
    struct ast_config *cfg;
    struct ast_variable *var;
    const char *tmp;
    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

    do {
        cfg = ast_config_load(config_file, config_flags);
        if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
            ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config_file);
            res = AST_MODULE_LOAD_DECLINE;
            break;
        } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
            break;

        var = ast_variable_browse(cfg, "global");
        if (!var) {
            /* nothing configured */
            break;
        }

        if ((tmp = ast_variable_retrieve(cfg, "global", "dsn")) == NULL) {
            ast_log(LOG_WARNING, "cdr_odbc: dsn not specified.  Assuming asteriskdb\n");
            tmp = "asteriskdb";
        }
        if (dsn)
            ast_free(dsn);
        dsn = ast_strdup(tmp);
        if (dsn == NULL) {
            res = -1;
            break;
        }

        if (((tmp = ast_variable_retrieve(cfg, "global", "dispositionstring"))) && ast_true(tmp))
            ast_set_flag(&config, CONFIG_DISPOSITIONSTRING);
        else
            ast_clear_flag(&config, CONFIG_DISPOSITIONSTRING);

        if (((tmp = ast_variable_retrieve(cfg, "global", "loguniqueid"))) && ast_true(tmp)) {
            ast_set_flag(&config, CONFIG_LOGUNIQUEID);
            ast_debug(1, "cdr_odbc: Logging uniqueid\n");
        } else {
            ast_clear_flag(&config, CONFIG_LOGUNIQUEID);
            ast_debug(1, "cdr_odbc: Not logging uniqueid\n");
        }

        if (((tmp = ast_variable_retrieve(cfg, "global", "usegmtime"))) && ast_true(tmp)) {
            ast_set_flag(&config, CONFIG_USEGMTIME);
            ast_debug(1, "cdr_odbc: Logging in GMT\n");
        } else {
            ast_clear_flag(&config, CONFIG_USEGMTIME);
            ast_debug(1, "cdr_odbc: Logging in local time\n");
        }

        if (((tmp = ast_variable_retrieve(cfg, "global", "hrtime"))) && ast_true(tmp)) {
            ast_set_flag(&config, CONFIG_HRTIME);
            ast_debug(1, "cdr_odbc: Logging billsec and duration fields as floats\n");
        } else {
            ast_clear_flag(&config, CONFIG_HRTIME);
            ast_debug(1, "cdr_odbc: Logging billsec and duration fields as integers\n");
        }

        if ((tmp = ast_variable_retrieve(cfg, "global", "table")) == NULL) {
            ast_log(LOG_WARNING, "cdr_odbc: table not specified.  Assuming cdr\n");
            tmp = "cdr";
        }
        if (table)
            ast_free(table);
        table = ast_strdup(tmp);
        if (table == NULL) {
            res = -1;
            break;
        }

        ast_verb(3, "cdr_odbc: dsn is %s\n", dsn);
        ast_verb(3, "cdr_odbc: table is %s\n", table);

        if (!ast_test_flag(&config, CONFIG_REGISTERED)) {
            res = ast_cdr_register(name, ast_module_info->description, odbc_log);
            if (res) {
                ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n");
            } else {
                ast_set_flag(&config, CONFIG_REGISTERED);
            }
        }
    } while (0);

    if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) {
        ast_cdr_unregister(name);
        ast_clear_flag(&config, CONFIG_REGISTERED);
    }

    if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
        ast_config_destroy(cfg);
    }
    return res;
}
Exemple #19
0
static int odbc_load_module(void)
{
	int res = 0;
	struct ast_config *cfg;
	struct ast_variable *var;
	char *tmp;

	ast_mutex_lock(&odbc_lock);

	cfg = ast_load(config);
	if (!cfg) {
		ast_log(LOG_WARNING, "cdr_odbc: Unable to load config for ODBC CDR's: %s\n", config);
		goto out;
	}
	
	var = ast_variable_browse(cfg, "global");
	if (!var) {
		/* nothing configured */
		goto out;
	}

	tmp = ast_variable_retrieve(cfg,"global","dsn");
	if (tmp) {
		dsn = malloc(strlen(tmp) + 1);
		if (dsn != NULL) {
			memset(dsn, 0, strlen(tmp) + 1);
			dsn_alloc = 1;
			strncpy(dsn, tmp, strlen(tmp));
		} else {
			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
			res = -1;
			goto out;
		}
	} else {
		ast_log(LOG_WARNING,"cdr_odbc: dsn not specified.  Assuming asteriskdb\n");
		dsn = "asteriskdb";
	}

	tmp = ast_variable_retrieve(cfg,"global","username");
	if (tmp) {
		username = malloc(strlen(tmp) + 1);
		if (username != NULL) {
			memset(username, 0, strlen(tmp) + 1);
			username_alloc = 1;
			strncpy(username, tmp, strlen(tmp));
		} else {
			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
			res = -1;
			goto out;
		}
	} else {
		ast_log(LOG_WARNING,"cdr_odbc: username not specified.  Assuming root\n");
		username = "******";
	}

	tmp = ast_variable_retrieve(cfg,"global","password");
	if (tmp) {
		password = malloc(strlen(tmp) + 1);
		if (password != NULL) {
			memset(password, 0, strlen(tmp) + 1);
			password_alloc = 1;
			strncpy(password, tmp, strlen(tmp));
		} else {
			ast_log(LOG_ERROR,"cdr_odbc: Out of memory error.\n");
			res = -1;
			goto out;
		}
	} else {
		ast_log(LOG_WARNING,"cdr_odbc: database password not specified.  Assuming blank\n");
		password = "";
	}

	tmp = ast_variable_retrieve(cfg,"global","loguniqueid");
	if (tmp) {
		loguniqueid = ast_true(tmp);
		if (loguniqueid) {
			ast_log(LOG_NOTICE,"cdr_odbc: Logging uniqueid\n");
		} else {
			ast_log(LOG_ERROR,"cdr_odbc: Not logging uniqueid\n");
		}
	} else {
		ast_log(LOG_WARNING,"cdr_odbc: Not logging uniqueid\n");
		loguniqueid = 0;
	}

	ast_destroy(cfg);
	if (option_verbose > 2) {
		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: dsn is %s\n",dsn);
		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: username is %s\n",username);
		ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: password is [secret]\n");
	}
	
	res = odbc_init();
	if (res < 0) {
		ast_log(LOG_ERROR, "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
		if (option_verbose > 2) {
			ast_verbose( VERBOSE_PREFIX_3 "cdr_odbc: Unable to connect to datasource: %s\n", dsn);
		}
	}
	res = ast_cdr_register(name, desc, odbc_log);
	if (res) {
		ast_log(LOG_ERROR, "cdr_odbc: Unable to register ODBC CDR handling\n");
	}
out:
	ast_mutex_unlock(&odbc_lock);
	return res;
}
Exemple #20
0
static int mongodb_load_module(int reload)
{
	int res = -1;
	struct ast_config *cfg = NULL;
   	mongoc_uri_t *uri = NULL;

	do {
		const char *tmp;
		struct ast_variable *var;
		struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };

		cfg = ast_config_load(CONFIG_FILE, config_flags);
		if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
			ast_log(LOG_WARNING, "unable to load config file=%s\n", CONFIG_FILE);
			res = AST_MODULE_LOAD_DECLINE;
			break;
		} 
		else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
			break;

		var = ast_variable_browse(cfg, CATEGORY);
		if (!var) {
			ast_log(LOG_WARNING, "no category specified.\n");
			break;
		}

		if ((tmp = ast_variable_retrieve(cfg, CATEGORY, URI)) == NULL) {
			ast_log(LOG_WARNING, "no uri specified.\n");
			break;
		}
	   	uri = mongoc_uri_new(tmp);
	   	if (uri == NULL) {
			ast_log(LOG_ERROR, "parsing uri error, %s\n", tmp);
			break;
	   	}

		if ((tmp = ast_variable_retrieve(cfg, CATEGORY, DATABSE)) == NULL) {
			ast_log(LOG_WARNING, "no database specified.\n");
			break;
		}
		if (dbname)
			ast_free(dbname);
		dbname = ast_strdup(tmp);
		if (dbname == NULL) {
			ast_log(LOG_ERROR, "not enough memory for dbname\n");
			break;
		}

		if ((tmp = ast_variable_retrieve(cfg, CATEGORY, COLLECTION)) == NULL) {
			ast_log(LOG_WARNING, "no collection specified.\n");
			break;
		}
		if (dbcollection)
			ast_free(dbcollection);
		dbcollection = ast_strdup(tmp);
		if (dbcollection == NULL) {
			ast_log(LOG_ERROR, "not enough memory for dbcollection\n");
			break;
		}

		if (!ast_test_flag(&config, CONFIG_REGISTERED)) {
			res = ast_cdr_register(NAME, ast_module_info->description, mongodb_log);
			if (res) {
				ast_log(LOG_ERROR, "unable to register CDR handling\n");
				break;
			}
			ast_set_flag(&config, CONFIG_REGISTERED);
		}

		if ((tmp = ast_variable_retrieve(cfg, CATEGORY, SERVERID)) != NULL) {
			if (!bson_oid_is_valid (tmp, strlen(tmp))) {
				ast_log(LOG_ERROR, "invalid server id specified.\n");
				break;
			}
			serverid = ast_malloc(sizeof(bson_oid_t));
		   	if (serverid == NULL) {
				ast_log(LOG_ERROR, "not enough memory\n");
				break;
	   		}
			bson_oid_init_from_string(serverid, tmp);
		}

		if (dbpool)
			mongoc_client_pool_destroy(dbpool);
	   	dbpool = mongoc_client_pool_new(uri);
	   	if (dbpool == NULL) {
			ast_log(LOG_ERROR, "cannot make a connection pool for MongoDB\n");
			break;
	   	}

	   	res = 0; // suceess
	} while (0);

	if (uri)
	   mongoc_uri_destroy(uri);
	if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dbname == NULL || dbcollection == NULL)) {
		ast_cdr_backend_suspend(NAME);
		ast_clear_flag(&config, CONFIG_REGISTERED);
	} 
	else
		ast_cdr_backend_unsuspend(NAME);
	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID)
		ast_config_destroy(cfg);
	return res;
}