You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gm...@apache.org on 2016/11/07 15:14:38 UTC

qpid-dispatch git commit: DISPATCH-352 initial implementation.

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 3eae0e137 -> 67c8b70c7


DISPATCH-352 initial implementation.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/67c8b70c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/67c8b70c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/67c8b70c

Branch: refs/heads/master
Commit: 67c8b70c7c18f59f148dca384c7a7d096201238c
Parents: 3eae0e1
Author: Roddie Kieley <rk...@redhat.com>
Authored: Thu Nov 3 23:28:21 2016 -0230
Committer: Roddie Kieley <rk...@redhat.com>
Committed: Thu Nov 3 23:28:21 2016 -0230

----------------------------------------------------------------------
 include/qpid/dispatch/dispatch.h          |  6 ++++
 router/src/main.c                         |  2 ++
 src/dispatch.c                            | 38 ++++++++++++++++++++++++++
 tests/config-0-empty/qdrouterd-empty.conf |  0
 tests/run_unit_tests.c                    |  7 +++++
 5 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/67c8b70c/include/qpid/dispatch/dispatch.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/dispatch.h b/include/qpid/dispatch/dispatch.h
index afc78b0..1e8b360 100644
--- a/include/qpid/dispatch/dispatch.h
+++ b/include/qpid/dispatch/dispatch.h
@@ -54,6 +54,12 @@ void qd_dispatch_free(qd_dispatch_t *qd);
  */
 qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path);
 
+/**
+ * Validate the configuration file.
+ *
+ * @param config_path The path to the configuration file.
+ */
+qd_error_t qd_dispatch_validate_config(const char *config_path);
 
 /**
  * @}

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/67c8b70c/router/src/main.c
----------------------------------------------------------------------
diff --git a/router/src/main.c b/router/src/main.c
index 969fc94..b8fc04b 100644
--- a/router/src/main.c
+++ b/router/src/main.c
@@ -120,6 +120,8 @@ static void main_process(const char *config_path, const char *python_pkgdir, int
     dispatch = qd_dispatch(python_pkgdir);
     check(fd);
     log_source = qd_log_source("MAIN"); /* Logging is initialized by qd_dispatch. */
+    qd_dispatch_validate_config(config_path);
+    check(fd);
     qd_dispatch_load_config(dispatch, config_path);
     check(fd);
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/67c8b70c/src/dispatch.c
----------------------------------------------------------------------
diff --git a/src/dispatch.c b/src/dispatch.c
index 902f097..16b2a40 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -95,6 +95,44 @@ qd_error_t qd_dispatch_load_config(qd_dispatch_t *qd, const char *config_path)
     return qd_error_code();
 }
 
+qd_error_t qd_dispatch_validate_config(const char *config_path)
+{
+	FILE* config_file = NULL;
+	char config_data = '\0';
+	qd_error_t validation_error = QD_ERROR_CONFIG;
+
+	do {
+		if (!config_path) {
+			validation_error = qd_error(QD_ERROR_VALUE, "Configuration path value was empty");
+			break;
+		}
+
+		config_file = fopen(config_path, "r");
+		if (!config_file) {
+			validation_error = qd_error(QD_ERROR_NOT_FOUND, "Configuration file could not be opened");
+			break;
+		}
+
+		// TODO Check the actual minimum number of bytes required for the smallest valid configuration file
+		if (!fread((void*)&config_data, 1, 1, config_file)) {
+			validation_error = qd_error(QD_ERROR_CONFIG, "Configuration file was empty");
+			break;
+		}
+
+		// TODO Add real validation code
+
+		validation_error = QD_ERROR_NONE;
+	} while (false); // do once
+
+	if (config_file)
+	{
+		fclose(config_file);
+	}
+
+	return validation_error;
+}
+
+
 /**
  * The Container Entity has been deprecated and will be removed in the future. Use the RouterEntity instead.
  */

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/67c8b70c/tests/config-0-empty/qdrouterd-empty.conf
----------------------------------------------------------------------
diff --git a/tests/config-0-empty/qdrouterd-empty.conf b/tests/config-0-empty/qdrouterd-empty.conf
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/67c8b70c/tests/run_unit_tests.c
----------------------------------------------------------------------
diff --git a/tests/run_unit_tests.c b/tests/run_unit_tests.c
index df4fe56..7a8b1d4 100644
--- a/tests/run_unit_tests.c
+++ b/tests/run_unit_tests.c
@@ -41,6 +41,13 @@ int main(int argc, char** argv)
 
     // Call qd_dispatch() first initialize allocator used by other tests.
     qd_dispatch_t *qd = qd_dispatch(0);
+
+    qd_dispatch_validate_config(argv[1]);
+    if (qd_error_code()) {
+        printf("Config failed: %s\n", qd_error_message());
+        return 1;
+    }
+
     qd_dispatch_load_config(qd, argv[1]);
     if (qd_error_code()) {
         printf("Config failed: %s\n", qd_error_message());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org