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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 3 08:55:32 CST 2009


Author: oej
Date: Tue Nov  3 08:55:28 2009
New Revision: 227161

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=227161
Log:
This code still crashes at load - when manager tries to register the custom function.

Must be an extremely simple mistake, something I totally fail to see at this point...

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=227161&r1=227160&r2=227161
==============================================================================
--- team/oej/manager-check-trunk/main/manager.c (original)
+++ team/oej/manager-check-trunk/main/manager.c Tue Nov  3 08:55:28 2009
@@ -685,6 +685,26 @@
 			For success returns, the module revision number is included.</para>
 		</description>
 	</manager>
+	<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>
+				Currently, the only spported  parameter is "sessions" which will return the current number of 
+				active sessions for this AMI account.
+			</para>
+		</description>
+	</function>
  ***/
 
 enum error_type {
@@ -5363,43 +5383,54 @@
 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) {
+	struct mansession_session *session;
+	struct ao2_iterator i;
+
+	i = ao2_iterator_init(sessions, 0);
+	while ((session = ao2_iterator_next(&i))) {
+		ao2_lock(session);
+		if (strcasecmp(session->username, login) == 0) {
 			no_sessions++;
 		}
-	}
-	AST_LIST_UNLOCK(&sessions);
+		ao2_unlock(session);
+		unref_mansession(session);
+	}
+
 
 	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)
+static int function_amiclient(struct ast_channel *chan, const 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);
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(name);
+		AST_APP_ARG(param);
+	);
+
+
+	if (ast_strlen_zero(data) ) {
+		ast_log(LOG_WARNING, "AMI_CLIENT() requires two arguments: AMI_CLIENT(<name>[,<arg>])\n");
+		return -1;
+	}
+	AST_STANDARD_APP_ARGS(args, data);
+
+	AST_RWLIST_RDLOCK(&users);
+	if (!(user = get_manager_by_name_locked(args.name))) {
+		AST_RWLIST_UNLOCK(&users);
+		ast_log(LOG_ERROR, "There's no manager user called : %s\n", args.name);
 		buf[0] = '\0';
 		return -1;
 	}
-	AST_LIST_UNLOCK(&users);
-
-	if (!strcasecmp(parameter, "sessions")) {
+	AST_RWLIST_UNLOCK(&users);
+
+	if (!strcasecmp(args.param, "sessions")) {
 		snprintf(buf, len, "%d", get_manager_sessions(data));
 	} else {
-		ast_log(LOG_ERROR, "Invalid arguments provided to function AMI_CLIENT: %s\n", data);
+		ast_log(LOG_ERROR, "Invalid arguments provided to function AMI_CLIENT: %s\n", args.param);
 		buf[0] = '\0';
 		return -1;
 
@@ -5408,28 +5439,6 @@
 	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 = {




More information about the asterisk-commits mailing list