thermferm/rdconfig.c

changeset 86
3d7a241329e2
parent 83
f99e9d6deff5
child 90
28ee293654fd
equal deleted inserted replaced
85:c3cc6e44d1a4 86:3d7a241329e2
86 defaultControlConstants(); 86 defaultControlConstants();
87 } 87 }
88 88
89 89
90 90
91 int wrconfig(char *confxml) 91 int wrconfig(void)
92 { 92 {
93 int rc = 0; 93 int rc = 0;
94 FILE *fp; 94 FILE *fp;
95 xmlTextWriterPtr writer; 95 xmlTextWriterPtr writer;
96 xmlBufferPtr buf; 96 xmlBufferPtr buf;
373 if (getenv((char *)"USER") == NULL) { 373 if (getenv((char *)"USER") == NULL) {
374 mypath = xstrcpy((char *)"/root"); 374 mypath = xstrcpy((char *)"/root");
375 } else { 375 } else {
376 mypath = xstrcpy(getenv((char *)"HOME")); 376 mypath = xstrcpy(getenv((char *)"HOME"));
377 } 377 }
378 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); 378 mypath = xstrcat(mypath, (char *)"/.thermferm/etc/");
379 mypath = xstrcat(mypath, confxml); 379 mkdirs(mypath, 0755);
380 mypath = xstrcat(mypath, (char *)"thermferm.xml");
380 381
381 if (debug) 382 if (debug)
382 fprintf(stdout, "Writing %s\n", mypath); 383 fprintf(stdout, "Writing %s\n", mypath);
383 384
384 if ((fp = fopen(mypath, "w")) == NULL) { 385 if ((fp = fopen(mypath, "w")) == NULL) {
677 return 0; 678 return 0;
678 } 679 }
679 680
680 681
681 682
682 int rdconfig(char *config) 683 int rdconfig(void)
683 { 684 {
684 int rc = 0, ival; 685 int rc = 0, ival;
685 xmlDocPtr doc; 686 xmlDocPtr doc;
686 xmlNodePtr cur; 687 xmlNodePtr cur;
687 xmlChar *key; 688 xmlChar *key;
695 if (getenv((char *)"USER") == NULL) { 696 if (getenv((char *)"USER") == NULL) {
696 mypath = xstrcpy((char *)"/root"); 697 mypath = xstrcpy((char *)"/root");
697 } else { 698 } else {
698 mypath = xstrcpy(getenv((char *)"HOME")); 699 mypath = xstrcpy(getenv((char *)"HOME"));
699 } 700 }
700 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); 701 mypath = xstrcat(mypath, (char *)"/.thermferm/etc/");
701 mypath = xstrcat(mypath, config); 702 mkdirs(mypath, 0755);
703 mypath = xstrcat(mypath, (char *)"thermferm.xml");
702 if ((doc = xmlParseFile(mypath)) == NULL) { 704 if ((doc = xmlParseFile(mypath)) == NULL) {
703 /* 705 /*
704 * Not in the users home directory 706 * Not in the users home directory
705 */ 707 */
706 free(mypath); 708 free(mypath);
707 mypath = xstrcpy((char *)"/etc/mbsepi-apps/"); 709 mypath = xstrcpy((char *)"/etc/mbsepi-apps/thermferm.xml");
708 mypath = xstrcat(mypath, config);
709 if ((doc = xmlParseFile(mypath)) == NULL) { 710 if ((doc = xmlParseFile(mypath)) == NULL) {
710 /* 711 /*
711 * Try /usr/local/etc 712 * Try /usr/local/etc
712 */ 713 */
713 free(mypath); 714 free(mypath);
714 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/"); 715 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/thermferm.xml");
715 mypath = xstrcat(mypath, config);
716 if ((doc = xmlParseFile(mypath)) == NULL) { 716 if ((doc = xmlParseFile(mypath)) == NULL) {
717 syslog(LOG_NOTICE, "rdconfig: could not parse %s", config); 717 syslog(LOG_NOTICE, "rdconfig: could not find thermferm.xml");
718 return 1; 718 return 1;
719 } 719 }
720 } 720 }
721 } 721 }
722 syslog(LOG_NOTICE, "rdconfig: using %s", mypath); 722 syslog(LOG_NOTICE, "rdconfig: using %s", mypath);

mercurial