+ 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



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45219 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 19 years ago
parent 5b52f69201
commit 5f395bf38f

@ -136,14 +136,15 @@ struct mansession {
/*! Execution thread */ /*! Execution thread */
pthread_t t; pthread_t t;
/*! Thread lock -- don't use in action callbacks, it's already taken care of */ /*! 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; ast_mutex_t __lock;
/*! socket address */ /*! socket address */
struct sockaddr_in sin; struct sockaddr_in sin;
/*! TCP socket */ /*! TCP socket */
int fd; 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; int busy;
/*! Whether or not we're "dead" */ /*! Whether or not we're "dead" XXX currently unused */
int dead; int dead;
/*! Whether an HTTP manager is in use */ /*! Whether an HTTP manager is in use */
int inuse; int inuse;
@ -1894,6 +1895,10 @@ static int action_userevent(struct mansession *s, struct message *m)
return 0; 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) static int process_message(struct mansession *s, struct message *m)
{ {
char action[80] = ""; char action[80] = "";
@ -1912,10 +1917,9 @@ static int process_message(struct mansession *s, struct message *m)
if (!ast_strlen_zero(id)) { if (!ast_strlen_zero(id)) {
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id); snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
} }
if (!s->authenticated) {
if (!strcasecmp(action, "Challenge")) { if (!strcasecmp(action, "Challenge")) {
char *authtype; char *authtype = astman_get_header(m, "AuthType");
authtype = astman_get_header(m, "AuthType");
if (!strcasecmp(authtype, "MD5")) { if (!strcasecmp(authtype, "MD5")) {
if (ast_strlen_zero(s->challenge)) if (ast_strlen_zero(s->challenge))
snprintf(s->challenge, sizeof(s->challenge), "%ld", ast_random()); snprintf(s->challenge, sizeof(s->challenge), "%ld", ast_random());
@ -1925,11 +1929,10 @@ static int process_message(struct mansession *s, struct message *m)
"Challenge: %s\r\n\r\n", "Challenge: %s\r\n\r\n",
idText, s->challenge); idText, s->challenge);
ast_mutex_unlock(&s->__lock); ast_mutex_unlock(&s->__lock);
return 0;
} else { } else {
astman_send_error(s, m, "Must specify AuthType"); astman_send_error(s, m, "Must specify AuthType");
return 0;
} }
return 0;
} else if (!strcasecmp(action, "Login")) { } else if (!strcasecmp(action, "Login")) {
if (authenticate(s, m)) { if (authenticate(s, m)) {
sleep(1); sleep(1);
@ -1944,13 +1947,10 @@ static int process_message(struct mansession *s, struct message *m)
} }
ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr)); 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"); 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; struct manager_action *tmp;
ast_mutex_lock(&s->__lock); ast_mutex_lock(&s->__lock);
s->busy++; s->busy++;

Loading…
Cancel
Save