[asterisk-commits] rizzo: trunk r45219 - /trunk/main/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Oct 16 07:00:54 MST 2006


Author: rizzo
Date: Mon Oct 16 09:00:53 2006
New Revision: 45219

URL: http://svn.digium.com/view/asterisk?rev=45219&view=rev
Log:
+ comment some unclear fields of struct mansession;

+ let some commands (Challenge, Login) be processed even if
  already authenticated, as it doesn't harm and prevents some
  incorrect error messages

+ remove custom code for Logoff - the existing handler was ok.

Some indentation fixes may be necessary


Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=45219&r1=45218&r2=45219&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Mon Oct 16 09:00:53 2006
@@ -136,14 +136,15 @@
 	/*! Execution thread */
 	pthread_t t;
 	/*! Thread lock -- don't use in action callbacks, it's already taken care of  */
+	/* XXX need to document which fields it is protecting */
 	ast_mutex_t __lock;
 	/*! socket address */
 	struct sockaddr_in sin;
 	/*! TCP socket */
 	int fd;
-	/*! Whether or not we're busy doing an action */
+	/*! Whether or not we're busy doing an action XXX currently useless */
 	int busy;
-	/*! Whether or not we're "dead" */
+	/*! Whether or not we're "dead" XXX currently unused */
 	int dead;
 	/*! Whether an HTTP manager is in use */
 	int inuse;
@@ -1894,6 +1895,10 @@
 	return 0;
 }
 
+/*
+ * Process the message, performing desired action.
+ * Return 0 on success, -1 on error that require the session to be destroyed.
+ */
 static int process_message(struct mansession *s, struct message *m)
 {
 	char action[80] = "";
@@ -1912,10 +1917,9 @@
 	if (!ast_strlen_zero(id)) {
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
 	}
-	if (!s->authenticated) {
 		if (!strcasecmp(action, "Challenge")) {
-			char *authtype;
-			authtype = astman_get_header(m, "AuthType");
+			char *authtype = astman_get_header(m, "AuthType");
+
 			if (!strcasecmp(authtype, "MD5")) {
 				if (ast_strlen_zero(s->challenge))
 					snprintf(s->challenge, sizeof(s->challenge), "%ld", ast_random());
@@ -1925,11 +1929,10 @@
 						"Challenge: %s\r\n\r\n",
 						idText, s->challenge);
 				ast_mutex_unlock(&s->__lock);
-				return 0;
 			} else {
 				astman_send_error(s, m, "Must specify AuthType");
-				return 0;
 			}
+			return 0;
 		} else if (!strcasecmp(action, "Login")) {
 			if (authenticate(s, m)) {
 				sleep(1);
@@ -1944,13 +1947,10 @@
 				}
 				ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr));
 				astman_send_ack(s, m, "Authentication accepted");
+				return 0;
 			}
-		} else if (!strcasecmp(action, "Logoff")) {
-			astman_send_ack(s, m, "See ya");
-			return -1;
-		} else
-			astman_send_error(s, m, "Authentication Required");
-	} else {
+		}
+	{
 		struct manager_action *tmp;
 		ast_mutex_lock(&s->__lock);
 		s->busy++;



More information about the asterisk-commits mailing list