[asterisk-commits] oej: branch oej/manager-check-trunk r227087 - /team/oej/manager-check-trunk/m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 3 02:56:25 CST 2009


Author: oej
Date: Tue Nov  3 02:56:22 2009
New Revision: 227087

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=227087
Log:
For some reason chan_sip doesn't compile on my Mac, it just hangs and NOISY_BUILD doesn't work. 
My laptop must have been affected by my cold... So this code might be junk. Beware.

Modified:
    team/oej/manager-check-trunk/main/manager.c

Modified: team/oej/manager-check-trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/manager-check-trunk/main/manager.c?view=diff&rev=227087&r1=227086&r2=227087
==============================================================================
--- team/oej/manager-check-trunk/main/manager.c (original)
+++ team/oej/manager-check-trunk/main/manager.c Tue Nov  3 02:56:22 2009
@@ -5359,6 +5359,84 @@
 	.key = __FILE__,
 };
 
+/*! \brief Get number of logged in sessions for a login name */
+static int get_manager_sessions(const char *login)
+{
+	int no_sessions = 0;
+	struct mansession_session *s;
+
+	/* Append event to master list and wake up any sleeping sessions */
+	AST_LIST_LOCK(&sessions);
+	AST_LIST_TRAVERSE(&sessions, s, list) {
+		if (strcasecmp(s->username, login) == 0) {
+			no_sessions++;
+		}
+	}
+	AST_LIST_UNLOCK(&sessions);
+
+	return no_sessions;
+}
+
+
+/*! \brief  ${AMI_CLIENT()} Dialplan function - reads manager client data */
+static int function_amiclient(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+	struct ast_manager_user *user = NULL;
+	char *parameter;
+
+	if ((parameter = strchr(data, '|')))
+		*parameter++ = '\0';
+
+	AST_LIST_LOCK(&users);
+	if (!(user = ast_get_manager_by_name_locked(data))) {
+		AST_LIST_UNLOCK(&users);
+		ast_log(LOG_ERROR, "There's no manager user called : %s\n", data);
+		buf[0] = '\0';
+		return -1;
+	}
+	AST_LIST_UNLOCK(&users);
+
+	if (!strcasecmp(parameter, "sessions")) {
+		snprintf(buf, len, "%d", get_manager_sessions(data));
+	} else {
+		ast_log(LOG_ERROR, "Invalid arguments provided to function AMI_CLIENT: %s\n", data);
+		buf[0] = '\0';
+		return -1;
+
+	}
+
+	return 0;
+}
+
+/*** DOCUMENTATION
+	<function name="AMI_CLIENT" language="en_US">
+		<synopsis>
+			Checks attributes of manager accounts
+		</synopsis>
+		<syntax>
+			<parameter name="loginname" required="true">
+				<para>Login name, specified in manager.conf</para>
+			</parameter>
+			<parameter name="parameter" required="true">
+				<para>Attribute to login name to return. 
+				</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>
+				Current parameter is only "sessions" which will return the current number of 
+				active sessions for this AMI account.
+			</para>
+		</description>
+	</function>
+***/
+
+/*! \brief description of AMI_CLIENT dialplan function */
+static struct ast_custom_function managerclient_function = {
+	.name = "AMI_CLIENT",
+	.read = function_amiclient,
+};
+
 static int registered = 0;
 static int webregged = 0;
 
@@ -5443,6 +5521,7 @@
 		ast_manager_register_xml("ModuleCheck", EVENT_FLAG_SYSTEM, manager_modulecheck);
 
 		ast_cli_register_multiple(cli_manager, ARRAY_LEN(cli_manager));
+		ast_custom_function_register(&managerclient_function);
 		ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
 		registered = 1;
 		/* Append placeholder event so master_eventq never runs dry */
@@ -5750,6 +5829,8 @@
 	return 0;
 }
 
+
+
 int init_manager(void)
 {
 	return __init_manager(0);




More information about the asterisk-commits mailing list