[asterisk-dev] [svn-commits] mmichelson: manager logout cli
Johansson Olle E
oej at edvina.net
Tue Feb 3 01:54:36 CST 2009
Some comments:
1. Please add a manager event to tell the user that he's logged out by
the CLI.
We might have other reasons to send this, like a shutdown.
2. Are we sure we can do this? If the manager client is in the middle
of receiving
a list of events - like 200 SIP peers - and someone logs him out
from the CLI,
will bad things happen in other parts of the code when the
mansession
disappears? Do we actually check for that? Does the locking code
here
take care of it properly?
Just being worried...
/O
3 feb 2009 kl. 00.10 skrev SVN commits to the Digium repositories:
> Author: mmichelson
> Date: Mon Feb 2 17:10:47 2009
> New Revision: 173028
>
> URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=173028
> Log:
> Add a CLI command to log out a manager user
>
> (closes issue #13877)
> Reported by: eliel
> Patches:
> cli_manager_logout.patch.txt uploaded by eliel (license 64)
> Tested by: eliel, putnopvut
>
>
> Modified:
> trunk/CHANGES
> trunk/main/manager.c
>
> Modified: trunk/CHANGES
> URL: http://svn.digium.com/svn-view/asterisk/trunk/CHANGES?view=diff&rev=173028&r1=173027&r2=173028
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/CHANGES (original)
> +++ trunk/CHANGES Mon Feb 2 17:10:47 2009
> @@ -295,6 +295,8 @@
>
> CLI Changes
> -----------
> + * New CLI command, "manager logout <username> [from <ipaddress>]"
> that will logout a
> + user manager based on the username and also (optional) on the
> ip address.
> * New CLI command, "config reload <file.conf>" which reloads any
> module that
> references that particular configuration file. Also added
> "config list"
> which shows which configuration files are in use.
>
> Modified: trunk/main/manager.c
> URL: http://svn.digium.com/svn-view/asterisk/trunk/main/manager.c?view=diff&rev=173028&r1=173027&r2=173028
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- trunk/main/manager.c (original)
> +++ trunk/main/manager.c Mon Feb 2 17:10:47 2009
> @@ -209,6 +209,8 @@
> /*! \brief list of hooks registered */
> static AST_RWLIST_HEAD_STATIC(manager_hooks, manager_custom_hook);
>
> +static void free_session(struct mansession *s);
> +
> /*! \brief Add a custom hook to be called when an event is fired */
> void ast_manager_register_hook(struct manager_custom_hook *hook)
> {
> @@ -646,6 +648,74 @@
> return CLI_SUCCESS;
> }
>
> +/*! \brief Implement CLI command 'manager logout <user>' */
> +static char *handle_managerlogout(struct ast_cli_entry *e, int cmd,
> struct ast_cli_args *a)
> +{
> + struct mansession *s = NULL;
> + char *ret = NULL;
> + size_t l;
> + int which = 0;
> + /*
> + char *choice[] = { "from", NULL };
> + */
> +
> + switch (cmd) {
> + case CLI_INIT:
> + e->command = "manager logout";
> + e->usage =
> + "Usage: manager logout <user> [from <ipaddress>]\n"
> + " Logout a connected manager user.\n";
> + return NULL;
> + case CLI_GENERATE:
> + /*
> + if (a->pos == 3) {
> + return ast_cli_complete(a->word, choice, a->n);
> + }
> + */
> + if (a->pos == 2) {
> + l = strlen(a->word);
> + AST_LIST_LOCK(&sessions);
> + AST_LIST_TRAVERSE(&sessions, s, list) {
> + if (!strncasecmp(a->word, s->username, l) && ++which > a->n ) {
> + ret = ast_strdup(s->username);
> + break;
> + }
> + }
> + AST_LIST_UNLOCK(&sessions);
> + }
> + return ret;
> + }
> +
> + if (a->argc != 3 && a->argc != 5) {
> + return CLI_SHOWUSAGE;
> + } else if (a->argc == 5 && strcasecmp(a->argv[3], "from")) {
> + return CLI_SHOWUSAGE;
> + }
> +
> + AST_LIST_LOCK(&sessions);
> + AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
> + if (!strcasecmp(s->username, a->argv[2])) {
> + if (a->argc == 5) {
> + /* compare ip address. */
> + if (strcmp(ast_inet_ntoa(s->sin.sin_addr), a->argv[4])) {
> + continue;
> + }
> + }
> + AST_LIST_REMOVE_CURRENT(list);
> + ast_mutex_lock(&s->__lock);
> + if (s->waiting_thread != AST_PTHREADT_NULL) {
> + pthread_kill(s->waiting_thread, SIGURG);
> + }
> + ast_mutex_unlock(&s->__lock);
> + ast_atomic_fetchadd_int(&num_sessions, -1);
> + free_session(s);
> + }
> + }
> + AST_LIST_TRAVERSE_SAFE_END;
> + AST_LIST_UNLOCK(&sessions);
> +
> + return CLI_SUCCESS;
> +}
>
> /*! \brief CLI command manager list commands */
> static char *handle_showmancmds(struct ast_cli_entry *e, int cmd,
> struct ast_cli_args *a)
> @@ -762,6 +832,7 @@
> AST_CLI_DEFINE(handle_showmanconn, "List connected manager
> interface users"),
> AST_CLI_DEFINE(handle_showmaneventq, "List manager interface queued
> events"),
> AST_CLI_DEFINE(handle_showmanagers, "List configured manager users"),
> + AST_CLI_DEFINE(handle_managerlogout, "Logout a manager user"),
> AST_CLI_DEFINE(handle_showmanager, "Display information on a
> specific manager user"),
> AST_CLI_DEFINE(handle_mandebug, "Show, enable, disable debugging of
> the manager code"),
> AST_CLI_DEFINE(handle_manager_reload, "Reload manager
> configurations"),
>
>
> _______________________________________________
> --Bandwidth and Colocation Provided by http://www.api-digital.com--
>
> svn-commits mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/svn-commits
---
* Olle E Johansson - oej at edvina.net
* Cell phone +46 70 593 68 51, Office +46 8 96 40 20, Sweden
More information about the asterisk-dev
mailing list