summaryrefslogtreecommitdiff
path: root/HouseControl.ino
diff options
context:
space:
mode:
authorMike Beattie <mike@ethernal.org>2012-03-28 06:50:13 +1300
committerMike Beattie <mike@ethernal.org>2012-03-28 06:50:13 +1300
commit61d861d207bbe8214929b4de914d044e205ad6ad (patch)
treed696edfd245331ceda1f519d12bb3a5410b9a04c /HouseControl.ino
parent9cb39288de8b3cf601265d9e3cc349e91ce4db70 (diff)
Add UTC offset parsing
Signed-off-by: Mike Beattie <mike@ethernal.org>
Diffstat (limited to 'HouseControl.ino')
-rw-r--r--HouseControl.ino16
1 files changed, 15 insertions, 1 deletions
diff --git a/HouseControl.ino b/HouseControl.ino
index 2dbf282..ce3a669 100644
--- a/HouseControl.ino
+++ b/HouseControl.ino
@@ -169,6 +169,17 @@ bool str_to_mac(byte *buf, byte *mac) {
return str_to_bytearray(buf,mac,16,6,':');
}
+bool verify_utcoffset(byte *buf, int *dest) {
+ int v, min;
+ char *next;
+ v = strtoul((char*)buf, &next, 10);
+ min = v % 100;
+ if ((v < -1200) || (v > 1400) || (min <= -60) || (min >= 60) || (next == (char*)buf))
+ return false;
+
+ *dest = v;
+ return true;
+}
/*********************************************************************************/
/* NTP/Time functions */
@@ -337,7 +348,7 @@ void configGetHandler(WebServer &server, WebServer::ConnectionType type, char *u
server.print("\",\"ntpserver\":\"");
server.print(ip_to_str(buf2, config.ntpServer));
- sprintf((char*)buf1, "\",\"utcoffset\":%d,\"stathost\":\"", config.UTC_offset);
+ sprintf((char*)buf1, "\",\"utcoffset\":\"%+05d\",\"stathost\":\"", config.UTC_offset);
server.print((char*)buf1);
server.print(ip_to_str(buf2, config.notifyHost));
@@ -370,6 +381,9 @@ void configSetHandler(WebServer &server, WebServer::ConnectionType type, char *u
if ((strcmp((const char*)buf2, "ntpserver") == 0))
if (!str_to_ip(buf1, config.ntpServer)) { server.print("Invalid NTP Server"); return; }
+ if ((strcmp((const char*)buf2, "utcoffset") == 0))
+ if (!verify_utcoffset(buf1, &config.UTC_offset)) { server.print("Invalid UTC offset"); return; }
+
if ((strcmp((const char*)buf2, "stathost") == 0))
if (!str_to_ip(buf1, config.notifyHost)) { server.print("Invalid Status target"); return; }