예제 #1
0
/**
 * Module initialization function that is called before the main process forks
 */
static int mod_init(void)
{
	int ver;
	db_url.len = strlen(db_url.s);

	if (db_url.len == 0) {
		if (use_uri_table) {
			LM_ERR("configuration error - no database URL, "
				"but use_uri_table is set!\n");
			return -1;
		}
		return 0;
	}

	db_table.len = strlen(db_table.s);
	uridb_user_col.len = strlen(uridb_user_col.s);
	uridb_domain_col.len = strlen(uridb_domain_col.s);
	uridb_uriuser_col.len = strlen(uridb_uriuser_col.s);

	if (uridb_db_bind(&db_url)) {
		LM_ERR("No database module found\n");
		return -1;
	}

	/* Check table version */
	ver = uridb_db_ver(&db_url, &db_table);
	if (ver < 0) {
		LM_ERR("Error while querying table version\n");
		return -1;
	} else {
		if (use_uri_table) {
			if (ver != URI_TABLE_VERSION) {
			LM_ERR("Invalid table version of the uri table\n");
			return -1;
			}
		} else {
			if (ver != SUBSCRIBER_TABLE_VERSION) {
			LM_ERR("Invalid table version of the subscriber table\n");
			return -1;
			}
		}
	}
	return 0;
}
예제 #2
0
/**
 * Module initialization function that is called before the main process forks
 */
static int mod_init(void)
{
	if (db_url.len == 0) {
		if (use_uri_table) {
			LM_ERR("configuration error - no database URL, "
				"but use_uri_table is set!\n");
			return -1;
		}
		return 0;
	}

	if (uridb_db_bind(&db_url)) {
		LM_ERR("No database module found\n");
		return -1;
	}

	/* Check table version */
	if (uridb_db_ver(&db_url) < 0) {
		LM_ERR("Error during database table version check");
		return -1;
	}
	return 0;
}
예제 #3
0
파일: uri_mod.c 프로젝트: ZRouter/ZRouter
static int mod_init(void)
{
	str proto_url;
	int checkver=-1;
	db_func_t db_funcs;
	db_con_t *db_conn = NULL;

	LM_DBG("initializing\n");

	init_db_url( db_url , 1 /*can be null*/);
	if (db_url.s) {
		if (db_url.len == 0) {
			if (use_uri_table != 0) {
				LM_ERR("configuration error - no database URL, "
					"but use_uri_table is set!\n");
				return -1;
			}
			return 0;
		}

		if (db_table.s == NULL) {
			/* no table set -> use defaults */
			if (use_uri_table != 0){
				db_table.s = URI_TABLE;
			}
			else {
				db_table.s = SUBSCRIBER_TABLE;
			}
		}

		db_table.len = strlen(db_table.s);
		uridb_user_col.len = strlen(uridb_user_col.s);
		uridb_domain_col.len = strlen(uridb_domain_col.s);
		uridb_uriuser_col.len = strlen(uridb_uriuser_col.s);

		if ( db_bind_mod(&db_url, &db_funcs) != 0 ) {
			LM_ERR("No database module found\n");
			return -1;
		}

		db_conn = db_funcs.init(&db_url);
		if( db_conn == NULL ) {
			LM_ERR("Could not connect to database\n");
			return -1;
		}

		checkver = db_check_table_version( &db_funcs, db_conn, &db_table,
			use_uri_table?URI_TABLE_VERSION:SUBSCRIBER_TABLE_VERSION );

		/** If checkver == -1, table validation failed */
		if( checkver == -1 ) {
			LM_ERR("Invalid table version.\n");
			db_funcs.close(db_conn);
			return -1;
		}

		db_funcs.close(db_conn);

		/* done with checkings - init the working connection */
		if (uridb_db_bind(&db_url)!=0) {
			LM_ERR("Failed to bind to a DB module\n");
			return -1;
		}
	}


	if (aaa_proto_url) {
		memset(attrs, 0, sizeof(attrs));
		memset(vals, 0, sizeof(vals));
		attrs[A_SERVICE_TYPE].name		= "Service-Type";
		attrs[A_USER_NAME].name			= "User-Name";

		if (use_sip_uri_host)
			attrs[A_SIP_URI_HOST].name	= "SIP-URI-Host";

		attrs[A_SIP_AVP].name			= "SIP-AVP";
		attrs[A_ACCT_SESSION_ID].name	= "Acct-Session-Id";
		vals[V_CALL_CHECK].name			= "Call-Check";

		proto_url.s = aaa_proto_url;
		proto_url.len = strlen(aaa_proto_url);

		if(aaa_prot_bind(&proto_url, &proto)) {
			LM_ERR("aaa protocol bind failure\n");
			return -1;
		}

		conn = proto.init_prot(&proto_url);
		if (!conn) {
			LM_ERR("aaa protocol initialization failure\n");
			return -2;
		}

		INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "uri", -3, -4);

		if (service_type != -1)
			vals[V_CALL_CHECK].value = service_type;
	}

	return 0;
}