Exemplo n.º 1
0
// return a bitmask: &SNM_MARKER_MASK: marker update, &SNM_REGION_MASK: region update
int UpdateMarkerRegionCache()
{
	int updateFlags=0;
	int i=0, x=0, num, col; double pos, rgnend; const char* name; bool isRgn;

	// added/updated markers/regions?
	while ((x = EnumProjectMarkers3(NULL, x, &isRgn, &pos, &rgnend, &name, &num, &col)))
	{
		MarkerRegion* m = g_mkrRgnCache.Get(i);
		if (!m || (m && !m->Compare(isRgn, pos, rgnend, name, num, col)))
		{
			if (m) g_mkrRgnCache.Delete(i, true);
			g_mkrRgnCache.Insert(i, new MarkerRegion(isRgn, pos, rgnend, name, num, col));
			updateFlags |= (isRgn ? SNM_REGION_MASK : SNM_MARKER_MASK);
		}
		i++;
	}
	// removed markers/regions?
	for (int j=g_mkrRgnCache.GetSize()-1; j>=i; j--) {
		if (MarkerRegion* m = g_mkrRgnCache.Get(j))
			updateFlags |= (m->IsRegion() ? SNM_REGION_MASK : SNM_MARKER_MASK);
		g_mkrRgnCache.Delete(j, true);
	}
	// project time mode update?
	static int sPrevTimemode = *(int*)GetConfigVar("projtimemode");
	if (updateFlags != (SNM_MARKER_MASK|SNM_REGION_MASK))
		if (int* timemode = (int*)GetConfigVar("projtimemode"))
			if (*timemode != sPrevTimemode) {
				sPrevTimemode = *timemode;
				return SNM_MARKER_MASK|SNM_REGION_MASK;
			}
	return updateFlags;
}
Exemplo n.º 2
0
void  Init_Backup_SQL( void ) {
	int	count;
	char	*dt, *tim, *backup;
	unsigned int	timeout_secs = 86400;

	backup = GetConfigVar( "mysql-backup" );
	if (*backup != 'y') { return; }

	mysql_init( &my_back_sql );
	mysql_options( &my_back_sql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout_secs );

	get_date_time(&dt,&tim);

	for( count=0; count<10; count++ ) {
		my_back_sock = mysql_real_connect( &my_back_sql,
			GetConfigVar( "mysql-backup-host" ),
			GetConfigVar( "mysql-backup-user" ),
			GetConfigVar( "mysql-backup-password" ),
			GetConfigVar( "mysql-backup-dhcp-database" ), 0, NULL, 0);
		if (my_back_sock) { return; }
		fprintf( stderr, "Can not connect to backup database server (attempt = %d)\n\n",
			(count + 1) );
		if (count < 9) sleep( 30 );
	}

	fprintf( stderr, "Can not connect to database server\n\n" );

	fprintf( stderr, "Config File: Host = '%s' \n", GetConfigVar( "mysql-backup-host" ) );
	fprintf( stderr, "Config File: User = '******' \n", GetConfigVar( "mysql-backup-user" ) );
	fprintf( stderr, "Config File: Password = '******' \n", GetConfigVar( "mysql-backup-password" ) );
	fprintf( stderr, "Config File: Dhcp-Database = '%s' \n",
		GetConfigVar( "mysql-backup-dhcp-database" ) );
	fprintf( stderr, "\n\n" );
}
Exemplo n.º 3
0
int ProjPrefsInit()
{
	SWSRegisterCommands(g_commandTable);

	g_prevautoxfade = *(int*)GetConfigVar("autoxfade");

	// Get saved default fade length
	char str[64];
	char strDef[64];
	sprintf(strDef, "%.8f", *(double*)GetConfigVar("deffadelen"));
	GetPrivateProfileString(SWS_INI, SAVED_DEF_FADE_LEN_KEY, strDef, str, 64, get_ini_file());
	g_dDefFadeLen = atof(str);

	return 1;
}
Exemplo n.º 4
0
// replace or paste items sub-chunk _tmpltItems
// _paste==false for replace, paste otherwise
// _p: optional (to factorize chunk updates)
bool ReplacePasteItemsFromTrackTemplate(MediaTrack* _tr, WDL_FastString* _tmpltItems, bool _paste, SNM_ChunkParserPatcher* _p)
{
	bool updated = false;
	if (_tr && _tr != GetMasterTrack(NULL) && _tmpltItems) // no items on master
	{
		SNM_ChunkParserPatcher* p = (_p ? _p : new SNM_ChunkParserPatcher(_tr));

		 // delete current items?
		if (!_paste)
			updated |= p->RemoveSubChunk("ITEM", 2, -1);

		// insert template items
		if (_tmpltItems->GetLength())
		{
			WDL_FastString tmpltItems(_tmpltItems); // do not alter _tmpltItems!

			// offset items if needed
			int* offsOpt = (int*)GetConfigVar("templateditcursor"); // >= REAPER v4.15
			if (offsOpt && *offsOpt)
			{
				double add = GetCursorPositionEx(NULL);
				SNM_ChunkParserPatcher pitems(&tmpltItems);
				pitems.ParsePatch(SNM_D_ADD, 1, "ITEM", "POSITION", -1, 1, &add);
			}

			p->GetChunk()->Insert(tmpltItems.Get(), p->GetChunk()->GetLength()-2); // -2: before ">\n"
			p->IncUpdates(); // as we directly work on the chunk
			updated = true;
		}

		if (!_p)
			DELETE_NULL(p); // + auto-commit if needed
	}
	return updated;
}
Exemplo n.º 5
0
bool SNM_SetIntConfigVar(const char* _varName, int _newVal) {
    if (int* pVar = (int*)(GetConfigVar(_varName))) {
        *pVar = _newVal;
        return true;
    }
    return false;
}
Exemplo n.º 6
0
bool SNM_SetDoubleConfigVar(const char* _varName, double _newVal) {
    if (double* pVar = (double*)(GetConfigVar(_varName))) {
        *pVar = _newVal;
        return true;
    }
    return false;
}
Exemplo n.º 7
0
bool MakeSingleTrackTemplateChunk(WDL_FastString* _in, WDL_FastString* _out, bool _delItems, bool _delEnvs, int _tmpltIdx, bool _obeyOffset)
{
	if (_in && _in->GetLength() && _out && _in!=_out)
	{
		_out->Set("");

		// truncate to the track #_tmpltIdx found in the template
		SNM_ChunkParserPatcher pin(_in);
		if (pin.GetSubChunk("TRACK", 1, _tmpltIdx, _out) >= 0)
		{
			int* offsOpt = _obeyOffset ? (int*)GetConfigVar("templateditcursor") : NULL; // >= REAPER v4.15

			// remove receives from the template as we deal with a single track
			// note: possible with multiple tracks in a same template file (w/ routings between those tracks)
			SNM_TrackEnvParserPatcher pout(_out);
			pout.RemoveLine("TRACK", "AUXRECV", 1, -1, "MIDIOUT");

			if (_delItems) // remove items from template (in one go)
				pout.RemoveSubChunk("ITEM", 2, -1);
			else if (offsOpt && *offsOpt) { // or offset them if needed
				double add = GetCursorPositionEx(NULL);
				pout.ParsePatch(SNM_D_ADD, 2, "ITEM", "POSITION", -1, 1, &add);
			}

			if (_delEnvs) // remove all envs from template (in one go)
				pout.RemoveEnvelopes();
			else if (offsOpt && *offsOpt) // or offset them if needed
				pout.OffsetEnvelopes(GetCursorPositionEx(NULL));
			return true;
		}
	}
	return false;
}
Exemplo n.º 8
0
void GetTimeSegmentPositions(TimeSegment timeSegment, double &dStartPos, double &dEndPos, MediaItem* item)
{
	double dOrgCursorPos = GetCursorPositionEx(0);
	bool bRefreshCurPos = false;

	switch(timeSegment)
	{
		case eTIMESEGMENT_TIMESEL:
			//Main_OnCommandEx(ID_GOTO_TIMESEL_END, 0, 0);
			//dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_TIMESEL_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			GetSet_LoopTimeRange2(0, false, false, &dStartPos, &dEndPos, false);
		break;
		case eTIMESEGMENT_SELITEM:
			if(item != NULL)
			{
				dStartPos = GetMediaItemInfo_Value(item, "D_POSITION");
				dEndPos = dStartPos + GetMediaItemInfo_Value(item, "D_LENGTH");
			}
			else
			{
				Main_OnCommandEx(ID_GOTO_SELITEM_END, 0, 0);
				dEndPos = GetCursorPositionEx(0);
				Main_OnCommandEx(ID_GOTO_SELITEM_START, 0, 0);
				dStartPos = GetCursorPositionEx(0);
				bRefreshCurPos = true;
			}
		break;
		case eTIMESEGMENT_LOOP:
			//Main_OnCommandEx(ID_GOTO_LOOP_END, 0, 0);
			//dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_LOOP_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			GetSet_LoopTimeRange2(0, false, true, &dStartPos, &dEndPos, false);
		break;
		case eTIMESEGMENT_PROJECT:
			Main_OnCommandEx(ID_GOTO_PROJECT_END, 0, 0);
			dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_PROJECT_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			dStartPos = *(int*)GetConfigVar("projtimeoffs");
			bRefreshCurPos = true;
		break;
		//case eTIMESEGMENT_CURRENTMEASURE:
		//	Main_OnCommandEx(ID_GOTO_CURMEASURE_START, 0, 0);
		//	dStartPos = GetCursorPositionEx(0);
		//	Main_OnCommandEx(ID_GOTO_NEXTMEASURE_START, 0, 0);
		//	dEndPos = GetCursorPositionEx(0);
		//break;
		default:
		break;
	}

	if(bRefreshCurPos)
		SetEditCurPos2(0, dOrgCursorPos, true, false);
}
Exemplo n.º 9
0
bool SNM_SendPatcher::NotifyChunkLine(int _mode, 
	LineParser* _lp, const char* _parsedLine, int _linePos, 
	int _parsedOccurence, WDL_PtrList<WDL_FastString>* _parsedParents,  
	WDL_FastString* _newChunk, int _updates)
{
	bool update = false;
	switch(_mode)
	{
		// add rcv
		case -1:
		{
			int defSndFlags = *(int*)GetConfigVar("defsendflag");
			bool audioSnd = ((defSndFlags & 512) != 512);
			bool midiSnd =  ((defSndFlags & 256) != 256);
			_newChunk->AppendFormatted(
				SNM_MAX_CHUNK_LINE_LENGTH,
				"AUXRECV %d %d %s %s 0 0 0 %d 0 -1.00000000000000 %d -1\n%s\n", 
				m_srcId-1, m_sendType, m_vol, m_pan, audioSnd?0:-1, midiSnd?0:31, _parsedLine);
			update = true;
			m_breakParsePatch = true;
		}
		break;

		// remove rcv
		case -2:
			update = (m_srcId > 0 && _lp->gettoken_int(1) == (m_srcId - 1));
			// update unchanged, i.e. we do not re-copy this receive
		break;

		// add "detailed" receive
		case -3:
		{
			SNM_SndRcv* mSndRcv = (SNM_SndRcv*)m_sndRcv;
			_newChunk->AppendFormatted(
				SNM_MAX_CHUNK_LINE_LENGTH,
				"AUXRECV %d %d %.14f %.14f %d %d %d %d %d %.14f %d %d\n%s\n", 
				m_srcId-1, 
				m_sendType, 
				mSndRcv->m_vol, 
				mSndRcv->m_pan,
				mSndRcv->m_mute,
				mSndRcv->m_mono,
				mSndRcv->m_phase,
				mSndRcv->m_srcChan,
				mSndRcv->m_destChan,
				mSndRcv->m_panl,
				mSndRcv->m_midi,
				-1, // API LIMITATION: cannot get snd/rcv automation
				_parsedLine);
			update = true;
			m_breakParsePatch = true;
		}
		break;
	}
	return update; 
}
Exemplo n.º 10
0
void  Log_Summerize( void ) {
	char		qbuf[500];
	char		*log_rotate, *oldlog_db;
	int		logrot = 0;

	log_rotate = GetConfigVar( "log-rotate-days" );
	if (*log_rotate == ' ') {
		fprintf(stderr,"log-rotate-days not configd\n" );
		return;
	}
	logrot = strtoul( log_rotate, NULL, 10 );
	if (logrot <= 0) return;

	oldlog_db = GetConfigVar( "mysql-oldlog-database" );
	if (*oldlog_db == ' ') {
		fprintf(stderr,"mysql-oldlog-database not configd\n" );
		return;
	}

	fprintf(stderr,"something something something\n" );
}
Exemplo n.º 11
0
int GetTrackVis(MediaTrack* tr) // &1 == mcp, &2 == tcp
{
	int iTrack = CSurf_TrackToID(tr, false);
	if (iTrack == 0)
		return *(int*)GetConfigVar("showmaintrack") ? 3 : 1; // For now, always return master vis in MCP
	else if (iTrack < 0)
		return 0;

	int iVis = *(bool*)GetSetMediaTrackInfo(tr, "B_SHOWINMIXER", NULL) ? 1 : 0;
	iVis    |= *(bool*)GetSetMediaTrackInfo(tr, "B_SHOWINTCP", NULL) ? 2 : 0;
	return iVis;
}
Exemplo n.º 12
0
void  InitSQLconnection() {
	char	*servid;

	server_id = strtoul( GetConfigVar( "server-id" ), NULL, 10 );
	if (server_id == 0) {
		fprintf(stderr,"!!! You need to set the Server-ID\n");
		fprintf(stderr,"I'm DYING!!!\n" );
		exit(0);
	}
	Init_Primary_SQL();
	Init_Backup_SQL();
	Init_PowerDNS_SQL();
}
Exemplo n.º 13
0
int main( void ) {
	char	*encoder_pref = NULL;

	ReadConfigFile( 0 );
	InitSQLconnection();

	encoder_pref = GetConfigVar( "config-encoder" );
	if (CheckExecutable( encoder_pref ) == 0) {
		printf("could not execute '%s'", encoder_pref );
		exit(1);
	}

	my_Check_New_Configs( encoder_pref );
	return 0;
}
Exemplo n.º 14
0
void  syslog_server( void ) {
	struct passwd	*pass_struct;
	char		*euid_pref, *dbhost_pref, *force_chroot;

	InitSQLconnection();
	my_LoadChecker();

	initSLogSocket();

	dbhost_pref = GetConfigVar( "mysql-host" );
	euid_pref = GetConfigVar( "effective-userid" );
	force_chroot = GetConfigVar( "force-localhost-chroot" );
	pass_struct = getpwnam( euid_pref );

	if (strcmp(dbhost_pref,"localhost") || !strcmp(force_chroot, "yes")) {
		// We cannot chroot if connect to the DB via
		// a unix socket vs tcp
		chroot( CHROOT_PATH );
	}
	if (pass_struct) {
		seteuid( pass_struct->pw_uid );
		setegid( pass_struct->pw_gid );
	}

	my_syslog( MLOG_SYSLOG, "docsis_server SYSLOG Version %s activated", VERSION);

	while(1) {
		// Update PID file
		update_pid_file();

		// ping the MySQL server
		my_SQL_Ping();

		getSLogPacket();
	}
}
Exemplo n.º 15
0
int GetEnvelopeOverlapState(TrackEnvelope* envelope, int* laneCount, int* envCount)
{
	bool lane, visible;
	visible = EnvVis(envelope, &lane);
	if (!visible || lane)
		return -1;

	int visEnvCount = CountVisibleTrackEnvelopesInTrackLane(GetEnvParent(envelope));
	int overlapMinHeight = *(int*)GetConfigVar("env_ol_minh");
	if (overlapMinHeight < 0)
		return (WritePtr(laneCount, visEnvCount), WritePtr(envCount, visEnvCount), 0);

	if (GetTrackEnvHeight(envelope, NULL, false) < overlapMinHeight)
		return (WritePtr(laneCount, 1), WritePtr(envCount, visEnvCount), (visEnvCount > 1) ? 2 : 1);

	return (WritePtr(laneCount, (visEnvCount > 1) ? visEnvCount : 1), WritePtr(envCount, (visEnvCount > 1) ? visEnvCount : 1), (visEnvCount > 1) ? 4 : 3);
}
Exemplo n.º 16
0
void SetTrackVis(MediaTrack* tr, int vis) // &1 == mcp, &2 == tcp
{
	int iTrack = CSurf_TrackToID(tr, false);
	if (iTrack == 0)
	{	// TODO - obey master in mcp
		if ((vis & 2) != (*(int*)GetConfigVar("showmaintrack") ? 2 : 0))
			Main_OnCommand(40075, 0);
	}
	else if (iTrack > 0)
	{
		if (vis != GetTrackVis(tr))
		{
			GetSetMediaTrackInfo(tr, "B_SHOWINTCP",   vis & 2 ? &g_bTrue : &g_bFalse);
			GetSetMediaTrackInfo(tr, "B_SHOWINMIXER", vis & 1 ? &g_bTrue : &g_bFalse);
		}
	}
}
Exemplo n.º 17
0
// ct->user: -1 left, 1 right
void MoveCursorSample(COMMAND_T* ct)
{
	double dPos = GetCursorPosition();
	int* pSrate = (int*)GetConfigVar("projsrate");
	if (!pSrate)
		return;
	double dSrate = (double)*pSrate;
	INT64 iCurSample = (INT64)(dPos * dSrate + 0.5);
	if (ct->user == -1 && (dPos == (double)(iCurSample / dSrate)))
		iCurSample--;
	else if (ct->user == 1)
		iCurSample++;

	double dNewPos = (double)(iCurSample / dSrate);

	SetEditCurPos(dNewPos, true, false);
}
Exemplo n.º 18
0
void TogDefFadeZero(COMMAND_T*)
{
	double* pdDefFade = (double*)GetConfigVar("deffadelen");
	if (*pdDefFade != 0.0)
	{
		if (*pdDefFade != g_dDefFadeLen)
		{
			char str[64];
			sprintf(str, "%.8f", *pdDefFade);
			WritePrivateProfileString(SWS_INI, SAVED_DEF_FADE_LEN_KEY, str, get_ini_file());
			g_dDefFadeLen = *pdDefFade;
		}
		*pdDefFade = 0.0;
	}
	else
	{
		*pdDefFade = g_dDefFadeLen;
	}
}
Exemplo n.º 19
0
bool GotoMarkerRegion(ReaProject* _proj, int _num, int _flags, bool _select = false)
{
	bool isrgn; double pos, end;
	int x=0, n; 
	while ((x = EnumProjectMarkers3(_proj, x, &isrgn, &pos, &end, NULL, &n, NULL)))
		if (n == _num && ((!isrgn && _flags&SNM_MARKER_MASK) || (isrgn && _flags&SNM_REGION_MASK)))
		{
			PreventUIRefresh(1);

			if (_select && isrgn && (_flags&SNM_REGION_MASK))
				GetSet_LoopTimeRange2(NULL, true, true, &pos, &end, false); // seek is managed below

			int* opt = (int*)GetConfigVar("smoothseek"); // obeys smooth seek
			SetEditCurPos2(_proj, pos, true, opt && *opt); // includes an undo point, if enabled in prefs

			PreventUIRefresh(-1);

			return true;
		}
	return false;
}
Exemplo n.º 20
0
void  my_LoadChecker( void ) {
	static int	fd = 0;
	char		buffer[1024], *loadchr, *p;
	float		avg;
	int		count;
	time_t		new_time;
	static time_t	old_time = 0;
	static float	my_LoadAvg = 0.0;
	static float	my_MaxLoad = 0.0;

	if (fd == 0) {
		fd = open ("/proc/loadavg", O_RDONLY);
	}
	if (fd == -1) { my_LoadAvg = 0; return; }

	new_time = time( NULL );
	if ( (new_time - old_time) > 15 ) {	// Check every 15 seconds

		loadchr = GetConfigVar( "suspend-load-avg" );
		if (*loadchr == ' ') { loadchr = "1.0"; }
		my_MaxLoad = atof( loadchr );

		memset( buffer, 0, 1024 );
		lseek( fd, 0, SEEK_SET );
		count = read (fd, buffer, sizeof(buffer));
		if (count <= 0) { my_LoadAvg = 0; return; }
		p = buffer;  while( *p != 0 && *p != ' ') { p++; }
		*p = 0;
		avg = atof( buffer );
		if (avg > my_MaxLoad && my_LoadAvg < my_MaxLoad) {
			my_syslog( MLOG_ERROR, "Load Average is too high. Suspending Logging. %3.3f", avg );
		}
		if (avg < my_MaxLoad && my_LoadAvg > my_MaxLoad) {
			my_syslog( MLOG_ERROR, "Load Average is OK. %3.3f", avg );
		}
		my_LoadAvg = avg;
		old_time = new_time;
	}
}
Exemplo n.º 21
0
// adds a receive (with vol & pan from source track for pre-fader)
// _srcTr:  source track (unchanged)
// _destTr: destination track
// _type:   reaper's type
//          0=Post-Fader (Post-Pan), 1=Pre-FX, 2=deprecated, 3=Pre-Fader (Post-FX)
// _p:      for multi-patch optimization, current destination track's SNM_SendPatcher
bool AddReceiveWithVolPan(MediaTrack * _srcTr, MediaTrack * _destTr, int _type, SNM_SendPatcher* _p)
{
	bool update = false;
	char vol[32] = "1.00000000000000";
	char pan[32] = "0.00000000000000";

	// if pre-fader, then re-copy track vol/pan
	if (_type == 3)
	{
		SNM_ChunkParserPatcher p(_srcTr, false);
		p.SetWantsMinimalState(true);
		if (p.Parse(SNM_GET_CHUNK_CHAR, 1, "TRACK", "VOLPAN", 0, 1, vol, NULL, "MUTESOLO") > 0 &&
			p.Parse(SNM_GET_CHUNK_CHAR, 1, "TRACK", "VOLPAN", 0, 2, pan, NULL, "MUTESOLO") > 0)
		{
			update = (_p->AddReceive(_srcTr, _type, vol, pan) > 0);
		}
	}

	// default volume
	if (!update && _snprintfStrict(vol, sizeof(vol), "%.14f", *(double*)GetConfigVar("defsendvol")) > 0)
		update = (_p->AddReceive(_srcTr, _type, vol, pan) > 0);
	return update;
}
Exemplo n.º 22
0
void CompressExpandPoints::doCommand(int flag)
{
    BR_Envelope envelope(GetSelectedEnvelope(NULL));
    if (envelope.CountSelected() < 2)
        return;

    double minVal, maxVal;
    envelope.GetSelectedPointsExtrema(&minVal, &maxVal);
    double midPoint = (maxVal + minVal) / 2;

    double p0; envelope.GetPoint(envelope.GetSelected(0), &p0, NULL, NULL, NULL);
    double pN; envelope.GetPoint(envelope.GetSelected(envelope.CountSelected()-1), &pN, NULL, NULL, NULL);
    if (p0 == pN)
        return; // same point in time

    double m = m_dGradientFactor * (m_dAmount - 1) * (pN - p0);

    if (envelope.IsTempo() && *(int*)GetConfigVar("tempoenvtimelock") == 1)
    {
        double t0, b0; int s0;
        envelope.GetPoint(0, &t0, &b0, &s0, NULL);
        double t0_old = t0;
        double b0_old = b0;

        for (int i = 0; i < envelope.CountPoints(); ++i)
        {
            double t1, b1; int s1;
            envelope.GetPoint(i, &t1, &b1, &s1, NULL);

            double newValue = b1;
            if (envelope.GetSelection(i) && b1 != midPoint)
            {
                double extremePoint = (b1 > midPoint) ? maxVal : minVal;
                double normalized = (b1 - midPoint) / (extremePoint - midPoint);
                normalized *= m * (t1 - p0) + m_dAmount;
                newValue = SetToBounds(normalized * ( extremePoint - midPoint) + midPoint, envelope.LaneMinValue(), envelope.LaneMaxValue());
            }

            double newTime = t1;
            if (s0 == SQUARE)
                newTime = t0 + ((t1 - t0_old) * b0_old) / b0;
            else
                newTime = t0 + ((t1 - t0_old) * (b0_old + b1)) / (b0 + newValue);

            t0 = newTime;
            b0 = newValue;
            s0 = s1;
            t0_old = t1;
            b0_old = b1;

            envelope.SetPoint(i, &newTime, &newValue, NULL, NULL);
        }
    }
    else
    {
        for (int i = 0; i < envelope.CountSelected(); ++i)
        {
            double position, value;
            envelope.GetPoint(envelope.GetSelected(i), &position, &value, NULL, NULL);

            if (value == midPoint)
               continue;

            double extremePoint = (value > midPoint) ? maxVal : minVal;
            double normalized = (value - midPoint) / (extremePoint - midPoint);
            normalized *= m * (position - p0) + m_dAmount;
            value = SetToBounds(normalized * ( extremePoint - midPoint) + midPoint, envelope.LaneMinValue(), envelope.LaneMaxValue());
            envelope.SetPoint(envelope.GetSelected(i), NULL, &value, NULL, NULL);
        }
    }

    envelope.Commit();
}
Exemplo n.º 23
0
void  Init_Primary_SQL( void ) {
	int	count;
	char	*dt, *tim;
	unsigned int	timeout_secs = 86400;

	mysql_init( &my_pri_sql );
	mysql_options( &my_pri_sql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout_secs );

	get_date_time(&dt,&tim);

	for( count=0; count<10; count++ ) {
		my_pri_sock = mysql_real_connect( &my_pri_sql,
			GetConfigVar( "mysql-host" ), GetConfigVar( "mysql-user" ),
			GetConfigVar( "mysql-password" ),
			GetConfigVar( "mysql-dhcp-database" ), 0, NULL, 0);
		if (my_pri_sock) { my_sock = my_pri_sock; return; }
		fprintf( stderr, "Can not connect to primary database server "
			"(attempt = %d)\nDB '%s', '%s', '%s', '%s'\n",
			(count + 1), GetConfigVar( "mysql-host" ), GetConfigVar( "mysql-user" ),
			GetConfigVar( "mysql-password" ), GetConfigVar( "mysql-dhcp-database" ) );
		if (count < 9) sleep( 30 );
	}

	fprintf( stderr, "Can not connect to database server\n\n" );

	fprintf( stderr, "Config File: Host = '%s' \n", GetConfigVar( "mysql-host" ) );
	fprintf( stderr, "Config File: User = '******' \n", GetConfigVar( "mysql-user" ) );
	fprintf( stderr, "Config File: Password = '******' \n", GetConfigVar( "mysql-password" ) );
	fprintf( stderr, "Config File: Dhcp-Database = '%s' \n", GetConfigVar( "mysql-dhcp-database" ) );
	fprintf( stderr, "\n\n" );
}
Exemplo n.º 24
0
double SNM_GetDoubleConfigVar(const char* _varName, double _errVal) {
    if (double* pVar = (double*)(GetConfigVar(_varName)))
        return *pVar;
    return _errVal;
}
Exemplo n.º 25
0
int SNM_GetIntConfigVar(const char* _varName, int _errVal) {
    if (int* pVar = (int*)(GetConfigVar(_varName)))
        return *pVar;
    return _errVal;
}
Exemplo n.º 26
0
void MoveCursorFade(COMMAND_T* ct)
{
	double dPos = GetCursorPosition();
	dPos += fabs(*(double*)GetConfigVar("deffadelen")) * (double)ct->user; // Abs because neg value means "not auto"
	SetEditCurPos(dPos, true, false);
}
Exemplo n.º 27
0
void dhcp_server( void ) {
	char			*iface_pref, *euid_pref, *dbhost_pref, *force_chroot;
	char			*dhcp_high_load_c;
	int			dhcp_high_load;
	dhcp_message		message;
	u_int32_t		server_ip;
	struct passwd		*pass_struct;
	int			retval = 0, cc = 0, sentreply;

	iface_pref = my_GetDHCPint();
	server_ip = getInterfaceIP( iface_pref );
	init_DHCP_Socket( server_ip );

//	euid_pref = GetConfigVar( "effective-userid" );
//	pass_struct = getpwnam( euid_pref );
//	if (pass_struct) {
//		seteuid( pass_struct->pw_uid );
//		setegid( pass_struct->pw_gid );
//	}

	dbhost_pref = GetConfigVar( "mysql-host" );
	force_chroot = GetConfigVar( "force-localhost-chroot" );
//	if (strcmp(dbhost_pref,"localhost") || !strcmp(force_chroot, "yes")) {
//		// We cannot chroot if connect to the DB via
//		// a unix socket vs tcp
//		chroot( CHROOT_PATH );
//	}

	dhcp_high_load_c = GetConfigVar( "dhcp-high-load" );
	if (*dhcp_high_load_c == ' ') { dhcp_high_load_c = "16"; }
	dhcp_high_load = strtoul( dhcp_high_load_c, NULL, 10 );
	if (dhcp_high_load <= 4) { dhcp_high_load = 4; }
	if (dhcp_high_load >= 128) { dhcp_high_load = 128; }
	my_Check_Load( dhcp_high_load );

	InitSQLconnection();

	my_syslog( MLOG_DHCP, "docsis_server DHCP version %s activated", VERSION);
	Clear_Remote_Commands();

	while (dhcpd_exit_flag) { /* loop until universe collapses */
		/* update the PID file */
		update_pid_file();

		/* Clear Message Struct */
		memset( &message, 0, sizeof( dhcp_message ) );

		retval = getPacket( &message );
		if (retval == -2) Check_Remote_Commands();
		if (retval < 0) {
			// ping the MySQL server
			my_SQL_Ping();
			continue;
		}
		message.server_ip = server_ip;

		if (Check_Canary) { fprintf(stderr,"canary A died %llu %llu %llu "
				" %llu %llu %llu  %llu %llu %llu\n",Canaries); continue; }

 		DecodeOptions( &message );
		if (message.in_opts.message_type == 0) {
			message.in_opts.message_type = DHCP_REQUEST;
		}

		if (Check_Canary) { fprintf(stderr,"canary B died %llu %llu %llu "
				" %llu %llu %llu  %llu %llu %llu\n",Canaries); continue; }

		sentreply = 0;
		switch( message.in_opts.message_type ) {
		case DHCP_DISCOVER:
			sentreply = send_Offer( &message );
			break;

		case DHCP_REQUEST:
			sentreply = send_ACK( &message );
			break;

		case DHCP_RELEASE:
			/* checkRelease( &message ); */
			break;
		case DHCP_INFORM:
			sentreply = send_ACK( &message );
			break;

		case DHCP_DECLINE:
			/* ignore */
			break;

		case DHCP_LEASE_QUERY:	/* wierd ubR thingy  0x0d */
			sentreply = leaseQuery( &message );
			break;

		default: {
			my_syslog(LOG_WARNING, "unsupported DHCP message (%02x) %s -- ignoring",
				message.in_opts.message_type, message.s_macaddr );
			}
		}

		if (Check_Canary) { fprintf(stderr,"canary C died %llu %llu %llu "
				" %llu %llu %llu  %llu %llu %llu\n",Canaries); continue; }

		if (sentreply) my_Check_Load( dhcp_high_load );
		Check_Remote_Commands();
	}

	my_syslog(LOG_INFO, "exit");
	Flush_ALL_SQL_Updates();
	closelog();
	exit(0);
}
Exemplo n.º 28
0
int send_positive_message( dhcp_message *message, int mess_type ) {
	static char	*newip_pref = NULL;
	u_int32_t	lease_time;
	ConfigNets	*netopts;

	/* check SQL table for this MAC address */
	my_findMAC( message );

	if (message->lease_type == LEASE_NOT_FOUND && message->in_opts.docsis_modem == 1 ) {
		my_syslog(LOG_INFO, "NAK -- unknown docsis modem: %s : %s ", message->s_macaddr,message->in_opts.vsi_model );
		// my_findMAC_CMUNKNOWN( message );
		send_NAK( message );
		return 1;
	}

	if (message->lease_type == LEASE_NOT_FOUND && message->in_opts.docsis_modem == 2 ) {
		my_syslog(LOG_INFO, "NAK -- unknown mta from modem: %s ", message->s_modem_macaddr);
		// message->lease_type = LEASE_REJECT;
		send_NAK( message );
		return 1;
	}

	if (message->lease_type == LEASE_REJECT) { return 0; }

	if (message->lease_type == LEASE_CPE &&
	    message->cpe_type == CPE_DYNAMIC &&
	    message->lockip == 0 &&
	    message->lease_time < 60 ) {
		// Your Lease has expired. You get a new IP!
		my_DeleteLease( message );
		message->lease_type = LEASE_NOT_FOUND;
	}

	if ( Verify_Vlan( message ) ) {
		if (message->lease_type == LEASE_CM ) {
			my_syslog(LOG_WARNING,
								"NEW CM GIaddr mismatch (the CM moved) gi %s ip %s vlan %d",
								message->in_giaddr, message->s_ipaddr, message->vlan );
			message->ipaddr = message->b_ipaddr = 0;
			message->s_ipaddr[0] = 0;
		}
    if (message->lease_type == LEASE_MTA ) {
      my_syslog(LOG_WARNING,
	              "NEW MTA GIaddr mismatch (the CM moved) gi %s ip %s vlan %d",
	              message->in_giaddr, message->s_ipaddr, message->vlan );
      message->ipaddr = message->b_ipaddr = 0;
      message->s_ipaddr[0] = 0;
    }
		if (message->lease_type == LEASE_CPE ) {
			my_syslog(LOG_WARNING, "NEW -- GIaddr does not match vlan - gi %s ip %s vlan %d",
				message->in_giaddr, message->s_ipaddr, message->vlan );
			if (message->cpe_type == CPE_STATIC) {
				my_DeleteLease( message );
				message->lease_type = LEASE_NOT_FOUND;
			} else {
				// if message->cpe_type == CPE_DYNAMIC
				my_DeleteLease( message ); /* added 29.11.2014 */
				message->lease_type = LEASE_NOAUTH;
			}
		}
	}

	if (message->lease_type == LEASE_NOT_FOUND && message->in_opts.agent_mac_len == 0) {
		my_syslog(LOG_WARNING, "NAK -- CPE asking for new IP directly - mac %s",
			message->s_macaddr );
		send_NAK( message );
		return 0;
	}

	if (newip_pref == NULL) newip_pref = GetConfigVar( "assign-new-ip" );

	if (message->lease_type == LEASE_NOT_FOUND) {
		if (*newip_pref == 'n') return 0;

		my_getNewIP_CPE( message );

		if (message->ipaddr == 0) {
			send_NAK( message );
			return 1;
		}
		if (message->lease_type == LEASE_CPE) {
			if (message->cpe_type == CPE_STATIC) {
				my_syslog(LOG_INFO, "NEW STATIC -- mac %s ip %s vlan %d",
					message->s_macaddr, message->s_ipaddr, message->vlan );
			}
			if (message->cpe_type == CPE_DYNAMIC) {
				my_syslog(LOG_INFO, "NEW DYNAMIC -- mac %s ip %s vlan %d",
					message->s_macaddr, message->s_ipaddr, message->vlan );
			}
		}
		if (message->lease_type == LEASE_NOAUTH) {
			my_syslog(LOG_INFO, "NEW NOAUTH -- mac %s ip %s vlan %d",
				message->s_macaddr, message->s_ipaddr, message->vlan );
                	send_NAK( message ); /* added 29.11.2014 */
                	return 1;
		}
	}

	if ( my_Get_Net( message ) ) {
		my_syslog(LOG_WARNING, "NAK -- no subnet for ip %s mac %s vlan %d, lease_type %d",
			message->s_ipaddr, message->s_macaddr, message->vlan, message->lease_type );
		send_NAK( message );
		return 1;
	}

	if (message->in_opts.request_addr != 0 ) {
		if (message->ipaddr != message->in_opts.request_addr ) {
			my_syslog(LOG_ERR, "WARN -- bad ip requested %s mac %s real-ip %s",
				message->in_opts.s_request_addr, message->s_macaddr, message->s_ipaddr );
		}
	}

	netopts = Get_Net_Opts( message->netptr );

	message->out_pack.op    = BOOTREPLY;
	message->out_pack.htype = ETH_10MB;
	message->out_pack.hlen  = ETH_10MB_LEN;
	message->out_pack.hops  = message->in_pack.hops;
	message->out_pack.flags = message->in_pack.flags;
	message->out_pack.xid   = message->in_pack.xid;

	message->out_pack.ciaddr = message->in_pack.ciaddr;
	message->out_pack.yiaddr = message->ipaddr;
	message->out_pack.siaddr = message->server_ip;
	message->out_pack.giaddr = message->in_pack.giaddr;
	message->out_pack.cookie = DHCP_MAGIC;

	memcpy( message->out_pack.macaddr, message->macaddr, 6 );

	initOpt( message );

	if (mess_type == DHCP_OFFER) {
		addOpt( 0x35, 0x01, "\x02");
	}
	if (mess_type == DHCP_ACK) {
		addOpt( 0x35, 0x01, "\x05");
	}

	// subnet mask
	addOpt( 0x01, 0x04, (char *) &(netopts->mask) );

	// gateway
	addOpt( 0x03, 0x04, (char *) &(netopts->gateway) );

	// Broadcast Address
	addOpt( 0x1c, 0x04, (char *) &(netopts->broadcast) );

	// Lease Times
        message->lease_time = netopts->lease_time;
        lease_time = htonl( message->lease_time );
        addOpt( 0x33, 0x04, (char *) &lease_time );
        lease_time = htonl( message->lease_time / 2 );
        addOpt( 0x3A, 0x04, (char *) &lease_time );
        lease_time = htonl( message->lease_time / 100 * 87.5 );
        addOpt( 0x3B, 0x04, (char *) &lease_time );


	addBigOpt( my_Get_Opt( 1, message->b_macaddr ) );
	addBigOpt( my_Get_Opt( message->opt, 0 ) );
	if (netopts->opt1 != message->opt)
		addBigOpt( my_Get_Opt( netopts->opt1, 0 ) );
	if (netopts->opt2 != message->opt)
		addBigOpt( my_Get_Opt( netopts->opt2, 0 ) );
	if (netopts->opt3 != message->opt)
		addBigOpt( my_Get_Opt( netopts->opt3, 0 ) );

	/* Config File Name */
	if (message->cfname != NULL && message->cfname[0] != 0) {
		strncpy( message->out_pack.file, message->cfname, 127 );
		addOpt( 0x43, strlen( message->out_pack.file ), message->cfname );
	} else {
		char	*cf = Lookup_ConfigOptsMacs(message,0x43);
		if (cf != NULL)
			strncpy( message->out_pack.file, cf, 127 );
	}

	/* Add Terminator */
	addOpt( 0xff, 0x00, NULL );

	my_dhcplog( mess_type, message );

	sendPacket( message );

	// if (mess_type == DHCP_OFFER &&
	if (message->lease_type == LEASE_CM) {
		// Update AgentID of cablemodem
		my_UpdateAgent( message );
	}
        if (message->lease_type == LEASE_MTA) {
                // Update AgentID of cablemodem
                my_UpdateAgent( message );
        }

	if (message->lease_type == LEASE_UNKNOWN) {
		// Update AgentID of cablemodem
		my_UpdateAgent( message );
	}

	/* if a customer pc, update the leases table, if a cable modem dont bother */
	if (message->lease_type == LEASE_CPE || message->lease_type == LEASE_NOAUTH ) {
		my_UpdateLease( message );
	}
	return 1;
}
Exemplo n.º 29
0
void ShowMaster(COMMAND_T* = NULL)
{
	if (GetConfigVar("showmaintrack") && !*(int*)GetConfigVar("showmaintrack"))
		Main_OnCommand(40075, 0);
}
Exemplo n.º 30
0
void tftp_server( void ) {
	int		cc;
	struct timeval	*tvp;
	time_t		last, hour6, min1;
	socklen_t	fromlen;
	struct sockaddr_in	from;
	struct timeval	tv;
	struct stat	tftp_stat;
	struct passwd	*pass_struct;
	char		*euid_pref, *tftp_dir, *dbhost_pref, *force_chroot;
	char		*tftp_high_load_c;
	int		tftp_high_load;
	fd_set		rfds;
	char		buf[SEGSIZE + 4];

	tftp_dir = my_GetTFTPdir();
	if ( stat( tftp_dir, &tftp_stat ) != 0 ) {
		fprintf(stderr,"Could not read tftp dir: %s", tftp_dir );
		exit(1);
	}
	chdir( tftp_dir );

	Init_TFTP_Socket();

	dbhost_pref = GetConfigVar( "mysql-host" );
	euid_pref = GetConfigVar( "effective-userid" );
	force_chroot = GetConfigVar( "force-localhost-chroot" );
	pass_struct = getpwnam( euid_pref );

	//if (strcmp(dbhost_pref,"localhost") || !strcmp(force_chroot, "yes")) {
		// We cannot chroot if connect to the DB via
		// a unix socket vs tcp
	//	chroot( tftp_dir );
	//}
	//if (pass_struct) {
	//	seteuid( pass_struct->pw_uid );
	//	setegid( pass_struct->pw_gid );
	//}

	tftp_high_load_c = GetConfigVar( "tftp-high-load" );
	if (*tftp_high_load_c == ' ') { tftp_high_load_c = "16"; }
	tftp_high_load = strtoul( tftp_high_load_c, NULL, 10 );
	if (tftp_high_load <= 4) { tftp_high_load = 4; }
	if (tftp_high_load >= 512) { tftp_high_load = 512; }
	my_Check_Load( tftp_high_load );

	InitSQLconnection();

	my_syslog( MLOG_TFTP, "docsis_server TFTP Version %s activated", VERSION );
	Clear_Remote_Commands();

	last = 0;
	hour6 = time(NULL);
	min1 = hour6;
	/* my_syslog( MLOG_TFTP, "tftp max num files %d", getdtablesize()); */

	while (tftpd_exit_flag) {
		// Update the PID file
		update_pid_file();

		FD_ZERO( &rfds );
		FD_SET( tftp_socket, &rfds );
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		tvp = &tv;

		if (select(tftp_socket + 1, &rfds, NULL, NULL, &tv ) < 0) {
			/* Don't choke when we get ptraced */
			if (errno == EINTR) continue;
			my_syslog( MLOG_ERROR, "tftp select: %s", strerror(errno) );
			exit(1);
		}


		if (FD_ISSET( tftp_socket, &rfds ) ) {
			/* Process a packet */
			fromlen = sizeof(from);
			cc = recvfrom(tftp_socket, buf, sizeof(buf), 0,
			    (struct sockaddr *)&from, &fromlen);
			if (cc < 0) {
				my_syslog( MLOG_ERROR, "tftp recvfrom: %s", strerror(errno) );
				continue;
			}

			/* Update now */
			now = time(NULL);

			/* Process this packet */
			process(&from, (struct tftphdr *)buf, cc);
			my_Check_Load( tftp_high_load );
		} else {
			now = time(NULL);
		}

		/* Run the timer list, no more than once a second */
		if (clientlistcnt > 0) {
			if (last != now) {
				last = now;
				runtimer();
			}
		}

		if ( (now - min1) >= 120) {
			min1 = now;
			free_file_cache();

			// ping the MySQL server
			my_SQL_Ping();
		}

		/* run the log stats 4 times a day */
		if ( (now - hour6) >= 21600) {
			hour6 = now;
			logstats();
		}
		Check_Remote_Commands();
	}
}