From 6fcbefff1cb97f297001f58c84026159a01d26e7 Mon Sep 17 00:00:00 2001 From: Kristof Szabados <Kristof.Szabados@ericsson.com> Date: Thu, 13 Dec 2018 19:22:08 +0100 Subject: [PATCH] lets allow to connect with a HC that reports its modules in a different order and provide some more information to find differences in md5 checksums (to let the C and Java side connect at the same time). Signed-off-by: Kristof Szabados <Kristof.Szabados@ericsson.com> --- mctr2/mctr/MainController.cc | 42 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/mctr2/mctr/MainController.cc b/mctr2/mctr/MainController.cc index 2d6309775..b15bcd4b4 100644 --- a/mctr2/mctr/MainController.cc +++ b/mctr2/mctr/MainController.cc @@ -818,10 +818,16 @@ boolean MainController::check_version(unknown_connection *conn) } for (int i = 0; i < n_modules; i++) { char *module_name = text_buf.pull_string(); - if (strcmp(module_name, modules[i].module_name)) { + int found_index = -1; + for (int j = 0; j < n_modules && found_index == -1; j++) { + if(!strcmp(module_name, modules[j].module_name)) { + found_index = j; + } + } + if (found_index == -1) { send_error(conn->fd, "The module number %d in this ETS (%s) " - "has different name than in the firstly connected ETS (%s).", - i, module_name, modules[i].module_name); + "has different name than any other module in the firstly connected ETS.", + i, module_name); delete [] module_name; return TRUE; } @@ -832,15 +838,31 @@ boolean MainController::check_version(unknown_connection *conn) module_checksum = new unsigned char[checksum_length]; text_buf.pull_raw(checksum_length, module_checksum); } else module_checksum = NULL; - if (checksum_length != modules[i].checksum_length || - memcmp(module_checksum, modules[i].module_checksum, - checksum_length)) checksum_differs = TRUE; - delete [] module_checksum; - if (checksum_differs) { + if (checksum_length != modules[found_index].checksum_length) { send_error(conn->fd, "The checksum of module %s in this ETS " - "is different than that of the firstly connected ETS.", - module_name); + "hass different length (%d) than that of the firstly connected ETS (%d).", + module_name, checksum_length, modules[found_index].checksum_length); + delete [] module_checksum; + delete [] module_name; + return TRUE; } + if (memcmp(module_checksum, modules[found_index].module_checksum, + checksum_length)) { + for (unsigned int j = 0; j < checksum_length; j++) { + if (module_checksum[j] != modules[found_index].module_checksum[j]) { + send_error(conn->fd, "At index %d the checksum of module %s in this ETS " + "is different (%d) than that of the firstly connected ETS (%d).", + j, module_name, module_checksum[j], modules[found_index].module_checksum[j]); + checksum_differs = TRUE; + } + } + if (checksum_differs) { + send_error(conn->fd, "The checksum of module %s in this ETS " + "is different than that of the firstly connected ETS.", + module_name); + } + } + delete [] module_checksum; delete [] module_name; if (checksum_differs) return TRUE; } -- GitLab