361 return 1; |
378 return 1; |
362 } |
379 } |
363 } |
380 } |
364 |
381 |
365 /* |
382 /* |
|
383 * Fermenting profiles |
|
384 */ |
|
385 if (Config.profiles) { |
|
386 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "PROFILES")) < 0) { |
|
387 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
|
388 return 1; |
|
389 } |
|
390 for (tmp4 = Config.profiles; tmp4; tmp4 = tmp4->next) { |
|
391 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "PROFILE")) < 0) { |
|
392 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
|
393 return 1; |
|
394 } |
|
395 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { |
|
396 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
397 return 1; |
|
398 } |
|
399 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", tmp4->uuid)) < 0) { |
|
400 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
401 return 1; |
|
402 } |
|
403 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp4->name)) < 0) { |
|
404 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
405 return 1; |
|
406 } |
|
407 if (tmp4->steps) { |
|
408 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "STEPS")) < 0) { |
|
409 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
|
410 return 1; |
|
411 } |
|
412 for (tmp5 = tmp4->steps; tmp5; tmp5 = tmp5->next) { |
|
413 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "STEP")) < 0) { |
|
414 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
|
415 return 1; |
|
416 } |
|
417 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { |
|
418 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
419 return 1; |
|
420 } |
|
421 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DURATION", "%d", tmp5->duration)) < 0) { |
|
422 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
423 return 1; |
|
424 } |
|
425 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TARGET", "%.1f", tmp5->target)) < 0) { |
|
426 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
427 return 1; |
|
428 } |
|
429 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
430 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
|
431 return 1; |
|
432 } |
|
433 } |
|
434 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
435 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
|
436 return 1; |
|
437 } |
|
438 } |
|
439 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
440 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
|
441 return 1; |
|
442 } |
|
443 } |
|
444 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
445 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
|
446 return 1; |
|
447 } |
|
448 } |
|
449 |
|
450 /* |
366 * All done, close any open elements |
451 * All done, close any open elements |
367 */ |
452 */ |
368 if ((rc = xmlTextWriterEndDocument(writer)) < 0) { |
453 if ((rc = xmlTextWriterEndDocument(writer)) < 0) { |
369 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndDocument"); |
454 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndDocument"); |
370 return 1; |
455 return 1; |
684 |
769 |
685 int parseFermenters(xmlDocPtr doc, xmlNodePtr cur) |
770 int parseFermenters(xmlDocPtr doc, xmlNodePtr cur) |
686 { |
771 { |
687 cur = cur->xmlChildrenNode; |
772 cur = cur->xmlChildrenNode; |
688 while (cur != NULL) { |
773 while (cur != NULL) { |
689 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT"))) { |
774 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT"))) { |
690 parseUnit(doc, cur); |
775 parseUnit(doc, cur); |
|
776 } |
|
777 cur = cur->next; |
|
778 } |
|
779 return 0; |
|
780 } |
|
781 |
|
782 |
|
783 |
|
784 int parseStep(xmlDocPtr doc, xmlNodePtr cur, prof_step **profstep) |
|
785 { |
|
786 xmlChar *key; |
|
787 int ival; |
|
788 float val; |
|
789 prof_step *step, *tmp; |
|
790 |
|
791 step = (prof_step *)malloc(sizeof(prof_step)); |
|
792 step->next = NULL; |
|
793 step->version = 1; |
|
794 step->duration = 0; |
|
795 step->target = 20.0; |
|
796 |
|
797 cur = cur->xmlChildrenNode; |
|
798 while (cur != NULL) { |
|
799 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) { |
|
800 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
801 if (xmlStrcmp(key, (const xmlChar *)"1")) { |
|
802 xmlFree(key); |
|
803 return 1; |
|
804 } |
|
805 step->version = 1; |
|
806 xmlFree(key); |
|
807 } |
|
808 if ((!xmlStrcmp(cur->name, (const xmlChar *)"DURATION"))) { |
|
809 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
810 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
811 step->duration = ival; |
|
812 xmlFree(key); |
|
813 } |
|
814 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TARGET"))) { |
|
815 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
816 if (sscanf((const char *)key, "%f", &val) == 1) |
|
817 step->target = val; |
|
818 xmlFree(key); |
|
819 } |
|
820 cur = cur->next; |
|
821 } |
|
822 |
|
823 if (*profstep == NULL) { |
|
824 *profstep = step; |
|
825 } else { |
|
826 for (tmp = *profstep; tmp; tmp = tmp->next) { |
|
827 if (tmp->next == NULL) { |
|
828 tmp->next = step; |
|
829 break; |
|
830 } |
|
831 } |
|
832 } |
|
833 return 0; |
|
834 } |
|
835 |
|
836 |
|
837 |
|
838 int parseSteps(xmlDocPtr doc, xmlNodePtr cur, prof_step **step) |
|
839 { |
|
840 cur = cur->xmlChildrenNode; |
|
841 while (cur != NULL) { |
|
842 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEP"))) { |
|
843 parseStep(doc, cur, step); |
|
844 } |
|
845 cur = cur->next; |
|
846 } |
|
847 return 0; |
|
848 } |
|
849 |
|
850 |
|
851 |
|
852 int parseProfile(xmlDocPtr doc, xmlNodePtr cur) |
|
853 { |
|
854 xmlChar *key; |
|
855 profiles_list *profile, *tmp; |
|
856 |
|
857 profile = (profiles_list *)malloc(sizeof(profiles_list)); |
|
858 profile->next = NULL; |
|
859 profile->version = 1; |
|
860 profile->uuid = profile->name = NULL; |
|
861 profile->steps = NULL; |
|
862 |
|
863 cur = cur->xmlChildrenNode; |
|
864 while (cur != NULL) { |
|
865 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) { |
|
866 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
867 if (xmlStrcmp(key, (const xmlChar *)"1")) { |
|
868 xmlFree(key); |
|
869 return 1; |
|
870 } |
|
871 profile->version = 1; |
|
872 xmlFree(key); |
|
873 } |
|
874 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { |
|
875 profile->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
876 } |
|
877 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { |
|
878 profile->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
879 } |
|
880 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEPS"))) { |
|
881 parseSteps(doc, cur, &(profile)->steps); |
|
882 } |
|
883 cur = cur->next; |
|
884 } |
|
885 |
|
886 if (Config.profiles == NULL) { |
|
887 Config.profiles = profile; |
|
888 } else { |
|
889 for (tmp = Config.profiles; tmp; tmp = tmp->next) { |
|
890 if (tmp->next == NULL) { |
|
891 tmp->next = profile; |
|
892 break; |
|
893 } |
|
894 } |
|
895 } |
|
896 |
|
897 return 0; |
|
898 } |
|
899 |
|
900 |
|
901 |
|
902 int parseProfiles(xmlDocPtr doc, xmlNodePtr cur) |
|
903 { |
|
904 cur = cur->xmlChildrenNode; |
|
905 while (cur != NULL) { |
|
906 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE"))) { |
|
907 parseProfile(doc, cur); |
691 } |
908 } |
692 cur = cur->next; |
909 cur = cur->next; |
693 } |
910 } |
694 return 0; |
911 return 0; |
695 } |
912 } |