[Patch 7/7] tabled: cleanup config.c re. empty elements

Pete Zaitcev <[email protected]>
Newsgroups org.kernel.vger.hail-devel
Message-ID <[email protected]>
I was changing it one by one, but honestly it was just stupid.
Let us change over to the sane checking once and for all.

Signed-Off-By: Pete Zaitcev <[email protected]>

---
 server/config.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

commit 1d6ca69e3f5f2cae0d5630e785f69549d93080e5
Author: Master <[email protected]>
Date:   Thu Jan 14 20:04:27 2010 -0700

    Switch cc->text checking completely to more precise variety.

diff --git a/server/config.c b/server/config.c
index 6fc7a88..301be66 100644
--- a/server/config.c
+++ b/server/config.c
@@ -158,7 +158,11 @@ static void cfg_elm_end (GMarkupParseContext *context,
 	struct stat statb;
 	long n;
 
-	if (!strcmp(element_name, "PID") && cc->text) {
+	if (!strcmp(element_name, "PID")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "PID element empty");
+			return;
+		}
 		if (tabled_srv.pid_file) {
 			/* Silent about command line override. */
 			free(cc->text);
@@ -168,13 +172,22 @@ static void cfg_elm_end (GMarkupParseContext *context,
 		cc->text = NULL;
 	}
 
-	else if (!strcmp(element_name, "ForceHost") && cc->text) {
+	else if (!strcmp(element_name, "ForceHost")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "ForceHost element empty");
+			return;
+		}
 		free(tabled_srv.ourhost);
 		tabled_srv.ourhost = cc->text;
 		cc->text = NULL;
 	}
 
-	else if (!strcmp(element_name, "TDB") && cc->text) {
+	else if (!strcmp(element_name, "TDB")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "TDB element empty");
+			return;
+		}
+
 		if (stat(cc->text, &statb) < 0) {
 			applog(LOG_ERR, "stat(2) on TDB '%s' failed: %s",
 			       cc->text, strerror(errno));
@@ -192,7 +205,12 @@ static void cfg_elm_end (GMarkupParseContext *context,
 		cc->text = NULL;
 	}
 
-	else if (!strcmp(element_name, "TDBRepPort") && cc->text) {
+	else if (!strcmp(element_name, "TDBRepPort")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "TDBRepPort element empty");
+			return;
+		}
+
 		n = strtol(cc->text, NULL, 10);
 		if (n <= 0 || n >= 65536) {
 			applog(LOG_WARNING,
@@ -244,8 +262,7 @@ static void cfg_elm_end (GMarkupParseContext *context,
 
 		if (cc->in_listen) {
 			n = strtol(cc->text, NULL, 10);
-			if ((n > 0 && n < 65536) ||
-			    !strcmp(cc->text, "auto")) {
+			if ((n > 0 && n < 65536) || !strcmp(cc->text, "auto")) {
 				free(cc->tmp_listen.port);
 				cc->tmp_listen.port = cc->text;
 			} else {
@@ -306,13 +323,21 @@ static void cfg_elm_end (GMarkupParseContext *context,
 		cc->text = NULL;
 	}
 
-	else if (!strcmp(element_name, "ChunkUser") && cc->text) {
+	else if (!strcmp(element_name, "ChunkUser")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "ChunkUser element empty");
+			return;
+		}
 		free(tabled_srv.chunk_user);
 		tabled_srv.chunk_user = cc->text;
 		cc->text = NULL;
 	}
 
-	else if (!strcmp(element_name, "ChunkKey") && cc->text) {
+	else if (!strcmp(element_name, "ChunkKey")) {
+		if (!cc->text) {
+			applog(LOG_WARNING, "ChunkKey element empty");
+			return;
+		}
 		free(tabled_srv.chunk_key);
 		tabled_srv.chunk_key = cc->text;
 		cc->text = NULL;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.