[Asterisk-code-review] manager.c: Simplify AMI ModuleCheck handling (asterisk[16])

Joshua Colp asteriskteam at digium.com
Fri Feb 11 11:54:37 CST 2022


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18005 )

Change subject: manager.c: Simplify AMI ModuleCheck handling
......................................................................

manager.c: Simplify AMI ModuleCheck handling

This code was needlessly complex and would fail to properly delimit
the response message if LOW_MEMORY was defined.

Change-Id: Iae50bf09ef4bc34f9dc4b49435daa76f8b2c5b6e
---
M main/manager.c
1 file changed, 13 insertions(+), 19 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  Kevin Harwell: Looks good to me, approved



diff --git a/main/manager.c b/main/manager.c
index 1a1016f..da10996 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -6474,36 +6474,30 @@
 /*! \brief Manager function to check if module is loaded */
 static int manager_modulecheck(struct mansession *s, const struct message *m)
 {
-	int res;
 	const char *module = astman_get_header(m, "Module");
 	const char *id = astman_get_header(m, "ActionID");
-	char idText[256];
-	char filename[PATH_MAX];
-	char *cut;
 
-	ast_copy_string(filename, module, sizeof(filename));
-	if ((cut = strchr(filename, '.'))) {
-		*cut = '\0';
-	} else {
-		cut = filename + strlen(filename);
-	}
-	snprintf(cut, (sizeof(filename) - strlen(filename)) - 1, ".so");
-	ast_debug(1, "**** ModuleCheck .so file %s\n", filename);
-	res = ast_module_check(filename);
-	if (!res) {
+	ast_debug(1, "**** ModuleCheck .so file %s\n", module);
+	if (!ast_module_check(module)) {
 		astman_send_error(s, m, "Module not loaded");
 		return 0;
 	}
 
+	astman_append(s, "Response: Success\r\n");
+
 	if (!ast_strlen_zero(id)) {
-		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
-	} else {
-		idText[0] = '\0';
+		astman_append(s, "ActionID: %s\r\n", id);
 	}
-	astman_append(s, "Response: Success\r\n%s", idText);
+
 #if !defined(LOW_MEMORY)
-	astman_append(s, "Version: %s\r\n\r\n", "");
+	/* When we switched from subversion to git we lost the ability to
+	 * retrieve the 'ASTERISK_FILE_VERSION' from that file, but we retain
+	 * the response header here for backwards compatibility. */
+	astman_append(s, "Version: \r\n");
 #endif
+
+	astman_append(s, "\r\n");
+
 	return 0;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18005
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Iae50bf09ef4bc34f9dc4b49435daa76f8b2c5b6e
Gerrit-Change-Number: 18005
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220211/8863cf5b/attachment.html>


More information about the asterisk-code-review mailing list