-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfiguration.cpp
More file actions
110 lines (91 loc) · 2.44 KB
/
Copy pathconfiguration.cpp
File metadata and controls
110 lines (91 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <string>
#include "configuration.hpp"
void HOMEKIT::ConfigurationFile_Write()
{
FILE * fp = fopen("configuration.txt", "w");
if(this->is_configured())
fprintf(fp, "configured=YES\n");
else
fprintf(fp, "configured=NO\n");
if(this->is_secured())
fprintf(fp, "pin=%s\n", (this->get_pin()).c_str());
fprintf(fp, "name=%s\n", (this->get_name()).c_str());
fprintf(fp, "id=%s\n", (this->get_id()).c_str());
fprintf(fp, "client_id=%s", (this->get_client_id()).c_str());
fclose(fp);
}
std::string read_untill(char delim, FILE * fp, char &symbol)
{
std::string field;
while(symbol != delim && symbol != EOF)
{
field+=symbol;
symbol = fgetc(fp);
}
symbol = fgetc(fp);
return field;
}
void HOMEKIT::ConfigurationFile_Read()
{
FILE * fp = fopen("configuration.txt", "r");
if(fp == NULL)
{
abort();
}
char symbol = fgetc(fp);
std::string field;
field = read_untill('=', fp, symbol);
while(symbol != EOF)
{
HOMEKIT device;
if(field == "configured")
{
this->config(true);
field.clear();
field = read_untill('\n', fp, symbol);
if(field == "NO")
{
fclose(fp);
return;
}
field.clear();
field = read_untill('=', fp, symbol);
}
if(field == "id")
{
field.clear();
field = read_untill('\n', fp, symbol);
this->set_id(field);
field.clear();
field = read_untill('=', fp, symbol);
}
if(field == "name")
{
field.clear();
field = read_untill('\n', fp, symbol);
this->set_name(field);
field.clear();
field = read_untill('=', fp, symbol);
}
if(field == "pin")
{
field.clear();
field = read_untill('\n', fp, symbol);
this->set_pin(field);
this->set_secure(true);
field.clear();
field = read_untill('=', fp, symbol);
}
if(field == "client_id")
{
field.clear();
field = read_untill('\n', fp, symbol);
this->set_client_id(field);
field.clear();
field = read_untill('=', fp, symbol);
}
}
fclose(fp);
return;
}