Subversion Repositories heating

Rev

Rev 3 | Rev 17 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 5
Line 46... Line 46...
46
 * The following functions read a config file and put the
46
 * The following functions read a config file and put the
47
 * contents into a structure.
47
 * contents into a structure.
48
 */
48
 */
49
void config::readConf(void)
49
void config::readConf(void)
50
{
50
{
51
	char confFile[512], line[512];
51
char confFile[512], line[512];
52
	char *home, *p;
52
char *home, *p;
53
	char hv0[64], hv1[128];
53
char hv0[64], hv1[128];
54
	bool gid = false;
54
bool gid = false;
55
	ifstream cfile;
55
ifstream cfile;
56
 
56
 
57
	// Initialize structure with default values
57
	// Initialize structure with default values
58
	strcpy(Configure.user, "nouser");
58
	strcpy(Configure.user, "nouser");
59
	strcpy(Configure.group, "nogroup");
59
	strcpy(Configure.group, "nogroup");
60
	strcpy(Configure.heatconf, "/etc/heating.d/heatconf.conf");
60
	strcpy(Configure.heatconf, "/etc/heating.d/heatconf.conf");
61
	strcpy(Configure.home, "/var/lib/heating/heating.db");
61
	strcpy(Configure.home, "/var/lib/heating/heating.db");
62
	strcpy(Configure.pidfile, "/var/run/heating.run");
62
	strcpy(Configure.pidfile, "/var/run/heating.run");
-
 
63
	strcpy(Configure.serial, "/dev/ttyAMA0");
63
	Configure.port = 11006;
64
	Configure.port = 11006;
64
	Configure.debug = true;
65
	Configure.debug = true;
65
	enableDebug(Configure.debug);
66
	enableDebug(Configure.debug);
66
	// Try to find a config file
67
	// Try to find a config file
67
	home = getenv("HOME");
68
	home = getenv("HOME");
68
	
69
 
69
	if (!access("/etc/heating.conf",R_OK))
70
	if (!access("/etc/heating.conf",R_OK))
70
		strcpy(confFile,"/etc/heating.conf");
71
		strcpy(confFile,"/etc/heating.conf");
71
	else if (!access("/etc/heating/heating.conf",R_OK))
72
	else if (!access("/etc/heating/heating.conf",R_OK))
72
		strcpy(confFile,"/etc/heating/heating.conf");
73
		strcpy(confFile,"/etc/heating/heating.conf");
73
	else if (!access("/usr/etc/heating.conf",R_OK))
74
	else if (!access("/usr/etc/heating.conf",R_OK))
74
		strcpy(confFile,"/usr/etc/heating.conf");
75
		strcpy(confFile,"/usr/etc/heating.conf");
75
	else if (home)
76
	else if (home)
76
	{
77
	{
77
		sprintf(confFile, "%s/.heating", home);
78
		sprintf(confFile, "%s/.heating", home);
78
		
79
 
79
		if (access(confFile,R_OK))
80
		if (access(confFile,R_OK))
80
			confFile[0] = 0;
81
			confFile[0] = 0;
81
	}
82
	}
82
	else
83
	else
83
	{
84
	{
84
		confFile[0] = 0;
85
		confFile[0] = 0;
85
		syslog(LOG_WARNING, "No config file was found!");
86
		syslog(LOG_WARNING, "No config file was found!");
86
		initialized = false;
87
		initialized = false;
87
		return;
88
		return;
88
	}
89
	}
89
	
90
 
90
	// If there's no config file, inform the user about it.
91
	// If there's no config file, inform the user about it.
91
	cfile.open(confFile, ios::in);
92
	cfile.open(confFile, ios::in);
92
	
93
 
93
	if ((cfile.rdstate() & std::ifstream::failbit) != 0)
94
	if ((cfile.rdstate() & std::ifstream::failbit) != 0)
94
	{
95
	{
95
		syslog(LOG_WARNING,"Error opening the config file: %s", strerror(errno));
96
		syslog(LOG_WARNING,"Error opening the config file: %s", strerror(errno));
96
		initialized = false;
97
		initialized = false;
97
		return;
98
		return;
Line 147... Line 148...
147
			strncpy(Configure.heatconf, hv1, sizeof(Configure.heatconf));
148
			strncpy(Configure.heatconf, hv1, sizeof(Configure.heatconf));
148
 
149
 
149
		if (!compcase(hv0, "Home"))
150
		if (!compcase(hv0, "Home"))
150
			strncpy(Configure.home, hv1, sizeof(Configure.home));
151
			strncpy(Configure.home, hv1, sizeof(Configure.home));
151
 
152
 
-
 
153
		if (!compcase(hv0, "Serial"))
-
 
154
			strncpy(Configure.serial, hv1, sizeof(Configure.serial));
-
 
155
 
152
		if (!compcase(hv0, "debug"))
156
		if (!compcase(hv0, "debug"))
153
		{
157
		{
154
			Configure.debug = atoi (hv1);
158
			Configure.debug = atoi (hv1);
155
			enableDebug(Configure.debug);
159
			enableDebug(Configure.debug);
156
		}
160
		}
157
	}
161
	}
158
	
162
 
159
	cfile.close ();
163
	cfile.close ();
160
	initialized = true;
164
	initialized = true;
161
}
165
}
162
 
166
 
163
CONFIGURE config::getConfig()
167
CONFIGURE config::getConfig()