brewco/rdsession.c

changeset 473
fdd30e935079
parent 472
55bcbf92ecab
child 474
fe1c3e3e90dc
--- a/brewco/rdsession.c	Tue Dec 22 21:07:14 2015 +0100
+++ b/brewco/rdsession.c	Sat Dec 26 21:45:44 2015 +0100
@@ -29,12 +29,11 @@
 extern char	*etcpath;
 
 
-const char      BREWSTEP[23][11] = { 	"NA", "INIT", "WATEROK", "PRIME", "WAITSTART",
-					"PREMASH", "MASHING", "IODINE", "REMOVE", "PREBOIL",
-					"BOIL", "BOILDONE", "HOPSTAND1", "COOLING1", "WHIRLPOOL1",
-					"COOLING2", "HOPSTAND2", "COOLING3", "HOPSTAND3", "COOLING",
-					"WHIRLPOOL", "CLEANUP", "DONE" };
-const char	MASHSTEP[5][8] = { "NA", "PROMPT", "HEATING", "REST", "DONE" };
+const char      BREWSTEP[16][10] = { 	"NA", "INIT", "WATEROK", "PRIME", "WAITSTART",
+					"PREMASH", "MASHING", "REMOVE", "PREBOIL", "BOIL",
+					"BOILDONE", "COOLING", "HOPSTAND", "WHIRLPOOL", "CLEANUP",
+					"DONE" };
+const char	MASHSTEP[8][11] = {	"MASH-IN", "PHYTASE", "GLUCANASE", "PROTEASE", "B-AMYLASE", "A-AMYLASE1", "A-AMYLASE2", "MASH-OUT" };
 
 #define MY_ENCODING "utf-8"
 
@@ -86,7 +85,11 @@
      * Start an element named "BREWCO". Since thist is the first
      * element, this will be the root element of the document.
      */
-    if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREWCO_BREW")) < 0) {
+    if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREWCO")) < 0) {
+	syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement");
+	return 1;
+    }
+    if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREW")) < 0) { 
 	syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement");
 	return 1;
     }
@@ -135,6 +138,14 @@
         return 1;
     }
 
+    /* 
+     * Close the element named BREW.
+     */
+    if ((rc = xmlTextWriterEndElement(writer)) < 0) {
+	syslog(LOG_NOTICE, "wrrecipes: error at xmlTextWriterEndElement");
+	return 1;
+    }
+
     /*
      * All done, close any open elements
      */
@@ -191,7 +202,7 @@
     int		i, ival;
     char	*mypath;
     xmlDocPtr	doc;
-    xmlNodePtr	cur;
+    xmlNodePtr	cur, s1cur;
     xmlChar	*key;
 
     /*
@@ -232,58 +243,66 @@
      */
     cur = cur->xmlChildrenNode;
     while (cur != NULL) {
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_RECIPE"))) {
-	    brew->uuid_recipe = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_UNIT"))) {
-	    brew->uuid_unit = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
-	    brew->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSTEP"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    for (i = 0; i < 23; i++) {
-		if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) {
-		    brew->brewstep = i;
-		    break;
+
+	if ((! xmlStrcmp(cur->name, (const xmlChar*)"BREW"))) {
+	    s1cur = cur->xmlChildrenNode;
+	    while (s1cur != NULL) {
+
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_RECIPE"))) {
+		    brew->uuid_recipe = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_UNIT"))) {
+		    brew->uuid_unit = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
 		}
-	    }
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTEP"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    for (i = 0; i < 5; i++) {
-		if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) {
-		    brew->mashstep = i;
-		    break;
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"NAME"))) {
+		    brew->name = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BREWSTEP"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    for (i = 0; i < 15; i++) {
+			if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) {
+			    brew->brewstep = i;
+			    break;
+			}
+		    }
+		    xmlFree(key);
 		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"MASHSTEP"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    for (i = 0; i < 8; i++) {
+			if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) {
+			    brew->mashstep = i;
+			    break;
+			}
+		    }
+		    xmlFree(key);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"TIMEOUT"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    if (sscanf((const char *)key, "%d", &ival) == 1)
+			brew->timeout = ival;
+		    xmlFree(key);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BOILTIMER"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    if (sscanf((const char *)key, "%d", &ival) == 1)
+			brew->boiltimer = ival;
+		    xmlFree(key);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"STARTTIME"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    if (sscanf((const char *)key, "%d", &ival) == 1)
+			brew->starttime = (time_t)ival;
+		    xmlFree(key);
+		}
+		if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"ENDTIME"))) {
+		    key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
+		    if (sscanf((const char *)key, "%d", &ival) == 1)
+			brew->endtime = (time_t)ival;
+		    xmlFree(key);
+		}
+		s1cur = s1cur->next;
 	    }
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMEOUT"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		brew->timeout = ival;
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILTIMER"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		brew->boiltimer = ival;
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"STARTTIME"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		brew->starttime = (time_t)ival;
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ENDTIME"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		brew->endtime = (time_t)ival;
-	    xmlFree(key);
 	}
 	cur = cur->next;
     }

mercurial