Beispiel #1
0
static int mod_init(void)
{
	/* Find a database module */
	if (group_db_bind(&db_url)) {
		return -1;
	}

	if (group_db_init(&db_url) < 0 ){
		LM_ERR("unable to open database connection\n");
		return -1;
	}

	/* check version for group table */
	if (db_check_table_version(&group_dbf, group_dbh, &table, TABLE_VERSION) < 0) {
			LM_ERR("error during group table version check.\n");
			return -1;
	}

	if (re_table.len) {
		/* check version for group re_group table */
		if (db_check_table_version(&group_dbf, group_dbh, &re_table, RE_TABLE_VERSION) < 0) {
			LM_ERR("error during re_group table version check.\n");
			return -1;
		}
		if (load_re( &re_table )!=0 ) {
			LM_ERR("failed to load <%s> table\n", re_table.s);
			return -1;
		}
	}

	group_db_close();
	return 0;
}
Beispiel #2
0
static int mod_init(void)
{
	LM_DBG("group module - initializing\n");

	/* check for a database module */
	if (db_url.s) {

		db_url.len = strlen(db_url.s);
		table.len = strlen(table.s);
		user_column.len = strlen(user_column.s);
		domain_column.len = strlen(domain_column.s);
		group_column.len = strlen(group_column.s);

		re_table.len = (re_table.s && re_table.s[0])?strlen(re_table.s):0;
		re_exp_column.len = strlen(re_exp_column.s);
		re_gid_column.len = strlen(re_gid_column.s);

		if (group_db_bind(&db_url)) {
			LM_ERR("unable to bind database module\n");
			return -1;
		}

		if (group_db_init(&db_url) < 0 ){
			LM_ERR("unable to open database connection\n");
			return -1;
		}

		/* check version for group table */
		if (db_check_table_version(&group_dbf, group_dbh, &table, TABLE_VERSION) < 0) {
			LM_ERR("error during group table version check.\n");
			return -1;
		}

		if (re_table.len) {
			/* check version for group re_group table */
			if (db_check_table_version(&group_dbf, group_dbh, &re_table, RE_TABLE_VERSION) < 0) {
				LM_ERR("error during re_group table version check.\n");
				return -1;
			}
			if (load_re( &re_table )!=0 ) {
				LM_ERR("failed to load <%s> table\n", re_table.s);
				return -1;
			}
		}

		group_db_close();

		LM_DBG("group database loaded\n");
	}

	/* check for an aaa module */
	if (aaa_proto_url.s) {

		aaa_proto_url.len = strlen(aaa_proto_url.s);

		memset(attrs, 0, sizeof(attrs));
		memset(vals, 0, sizeof(vals));
		attrs[A_SERVICE_TYPE].name		= "Service-Type";
		attrs[A_USER_NAME].name			= "User-Name";
		attrs[A_SIP_GROUP].name			= "Sip-Group";
		attrs[A_ACCT_SESSION_ID].name	= "Acct-Session-Id";
		vals[V_GROUP_CHECK].name		= "Group-Check";

		if (aaa_prot_bind(&aaa_proto_url, &proto)) {
			LM_ERR("unable to bind aaa protocol module\n");
			return -1;
		}

		if (!(conn = proto.init_prot(&aaa_proto_url))) {
			LM_ERR("unable to initialize aaa protocol module\n");
			return -1;
		}

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

		LM_DBG("aaa protocol module loaded\n");
	}

	return 0;
}
Beispiel #3
0
void OscReceiver::processMixerMessage(const std::string addr, const osc::ReceivedMessage& m){
	boost::regex mixer_re("^/(\\d+)/(.+)");
	boost::regex volume_re("^volume(/relative){0,1}/{0,1}$");
	boost::regex mute_re("^mute(/toggle){0,1}/{0,1}$");
	boost::regex eq_re("^eq/(high|mid|low)(/relative|/cut|/cut/toggle){0,1}/{0,1}$");
	boost::regex load_re("^load/{0,1}$");
	boost::cmatch matches;
	osc::ReceivedMessage::const_iterator arg_it = m.ArgumentsBegin();

	if(boost::regex_match(addr.c_str(), matches, mixer_re)){
		unsigned int mixer = (unsigned int)atoi(matches[1].str().c_str());
		std::string remain(matches[2].str());
		//make sure we're in range
		if(mixer >= mModel->numMixerChannels())
			return;
		if(boost::regex_match(remain.c_str(), matches, volume_re)){
			//make sure our matches list is long enough and that we have an argument
			if(matches.size() == 2 && arg_it != m.ArgumentsEnd()){
				float num = floatFromOscNumber(*arg_it);
				//"" == absolute, otherwise, relative
				if(strcmp("", matches[1].str().c_str()) == 0)
					mModel->mixerChannels()->at(mixer)->setVolume(num);
				else {
					mModel->mixerChannels()->at(mixer)->setVolume(
							mModel->mixerChannels()->at(mixer)->volume() + num);
				}
			} else
				throw osc::MissingArgumentException();
		} else if(boost::regex_match(remain.c_str(), matches, mute_re)){
			//make sure our matches list is long enough to test
			if(matches.size() == 2){
				//if we have no argument then we're just setting the mute
				//otherwise toggle mute
				if(strcmp("", matches[1].str().c_str()) == 0) {
					if(arg_it != m.ArgumentsEnd())
						mModel->mixerChannels()->at(mixer)->setMuted(boolFromBoolOrInt(*arg_it));
					else 
						throw osc::MissingArgumentException();
				} else {
					mModel->mixerChannels()->at(mixer)->setMuted(
							!mModel->mixerChannels()->at(mixer)->muted());
				}
			}
		} else if(boost::regex_match(remain.c_str(), matches, eq_re)){
			if(matches.size() == 3){
				EQModel * eqModel = mModel->mixerChannels()->at(mixer)->eq();
				//figure out the band
				EQModel::band band;
				if(strcmp(matches[1].str().c_str(), "low") == 0)
					band = EQModel::LOW;
				else if(strcmp(matches[1].str().c_str(), "mid") == 0)
					band = EQModel::MID;
				else
					band = EQModel::HIGH;

				if(strcmp(matches[2].str().c_str(), "") == 0){
					//absolute
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else
						eqModel->set(band, floatFromOscNumber(*arg_it));
				} else if(strcmp(matches[2].str().c_str(), "/cut") == 0){
					//cut
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else
						eqModel->cut(band, boolFromBoolOrInt(*arg_it));
				} else if(strcmp(matches[2].str().c_str(), "/cut/toggle") == 0){
					//toggle cut
					eqModel->toggleCut(band);
				} else {
					//otherwise it is relative
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else {
						eqModel->set(band, 
								eqModel->value(band) + floatFromOscNumber(*arg_it));
					}
				}
			}
		} else if(boost::regex_match(remain.c_str(), load_re)){
			if(arg_it == m.ArgumentsEnd())
				throw osc::MissingArgumentException();
			int work = intFromOsc(*arg_it);
			mModel->mixerChannels()->at(mixer)->loadWork(work);
			//otherwise it is a djmixer control message [or not valid]
		} else {
			processDJControlMessage(remain.c_str(), mModel->mixerChannels()->at(mixer)->control(), m);
		}
	}
}