thermferm/rdconfig.c

changeset 540
5a26429abbf8
parent 534
92b546d4a839
child 553
4091d4fe217f
--- a/thermferm/rdconfig.c	Mon Jul 16 11:41:46 2018 +0200
+++ b/thermferm/rdconfig.c	Mon Jul 16 17:23:22 2018 +0200
@@ -75,6 +75,9 @@
     if (Config.mqtt_password)
 	free(Config.mqtt_password);
     Config.mqtt_password = NULL;
+    if (Config.uuid)
+	free(Config.uuid);
+    Config.uuid = NULL;
  
     for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) {
 	if (tmp2->uuid)
@@ -219,6 +222,10 @@
 	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 	return 1;
     }
+    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.uuid)) < 0) {
+	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+	return 1;
+    }
     if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port)) < 0) {
 	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 	return 1;
@@ -2219,6 +2226,9 @@
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"MQTT_PASS"))) {
 	    Config.mqtt_password = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) {
+	    Config.uuid= (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) {
 	    parseLCDs(doc, cur);
 	}
@@ -2243,6 +2253,17 @@
     free(mypath);
     mypath = NULL;
 
+    /*
+     * If the system uuid is not set, do it now.
+     */
+    if (Config.uuid == NULL) {
+	uuid_t		uu;
+
+	Config.uuid = malloc(37);
+	uuid_generate(uu);
+	uuid_unparse(uu, Config.uuid);
+    }
+
     return rc;
 }
 

mercurial