#define TDLPWD		""

/*
 *  tdlight.vdl $Revision: 10$ $Date: 15.03.2004 13:36:15$
 *
 *	The user .tdlight must exist and should have highest priority.
 *
 *	User config variables (of user .tdlight):
 *
 *  TDLENABLE	Enable the control of light.
 *
 *	TDLNRON		The number to dial to turn the light on.  (With N or A)
 *	TDLNROFF	The number to dial to turn the light off. (With N or A)
 *
 *           effective_number_to_dial = nron | nroff
 *           calling_party_number     = user_conf TDLCPI of the resolved user
 *
 *
 *	TDLDELAY	Delay of receive light trigger in seconds. (Default 90)
 *
 *	Script defines:
 *
 *	TDLPWD		The password of user FAXADM
 *
 */

#include "lib.h"

void GetVal(char *buf, int len, FILE *fd)
{
	char *h;
	int   l;

	fgets(buf, len, fd);
	for (l = 0; l < strlen(buf); l++)
	{
		if (buf[l] == '\r') buf[l] = 0;
		if (buf[l] == '\n') buf[l] = 0;
	}
}

void Main()
{
	DRVERR  res;
	FILE   *fd;
	char    szDataFile[1024];
	char    szTemp[128];
	char    szHost[128];
	char    szUser[128];
	char    szNumb[128];
	USER    User;
	char    szNrOn [128];
	char    szNrOff[128];
	int     on;
	char   *pszNr;

	GetDataFile(szDataFile);

	fd = fopen(szDataFile, "r");

	GetVal(szTemp, sizeof(szTemp), fd); // skip scriptname
	GetVal(szHost, sizeof(szHost), fd);
	GetVal(szUser, sizeof(szUser), fd);
	GetVal(szNumb, sizeof(szNumb), fd);

	strcpy(User.szHost, szHost);
	strcpy(User.szID, ".tdlight");

	GetUserProperty2(&User, "TDLNRON",  szNrOn );
	GetUserProperty2(&User, "TDLNROFF", szNrOff);

	if ((res = TDataCheck(TDLPWD, szHost, szUser, &on)))
	{
		Exit(res);
	}
	else
	{
		pszNr = on ? szNrOn : szNrOff;

		if ((res = Dial(pszNr)))
		{
			if (res != 0x20001000)
			{
				Exit(res);
			}
		}

		SetDeleteAfterSend(1);

		/*
		SayTTS("Durchwahl:");
		SayTTS(szNumb);

		if (on)
		{
			SayTTS("Licht an!");
		}
		else
		{
			SayTTS("Licht aus!");
		}
		*/
	}

	if (fd)
	{
		fclose(fd);
	}
}
