[asterisk-commits] russell: branch 1.4 r51750 -
/branches/1.4/main/manager.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Jan 23 14:33:16 MST 2007
Author: russell
Date: Tue Jan 23 15:33:15 2007
New Revision: 51750
URL: http://svn.digium.com/view/asterisk?view=rev&rev=51750
Log:
When traversing the list of manager actions, the iterator needs to be
initialized to the list head *after* locking the list. Also, lock the actions
list in one place it is being accessed where it was not being done.
Modified:
branches/1.4/main/manager.c
Modified: branches/1.4/main/manager.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/manager.c?view=diff&rev=51750&r1=51749&r2=51750
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Tue Jan 23 15:33:15 2007
@@ -426,7 +426,7 @@
static int handle_showmancmd(int fd, int argc, char *argv[])
{
- struct manager_action *cur = first_action;
+ struct manager_action *cur;
char authority[80];
int num;
@@ -434,7 +434,7 @@
return RESULT_SHOWUSAGE;
ast_mutex_lock(&actionlock);
- for (; cur; cur = cur->next) { /* Walk the list of actions */
+ for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
for (num = 3; num < argc; num++) {
if (!strcasecmp(cur->action, argv[num])) {
ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", cur->action, cur->synopsis, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->description ? cur->description : "");
@@ -521,7 +521,7 @@
Should change to "manager show commands" */
static int handle_showmancmds(int fd, int argc, char *argv[])
{
- struct manager_action *cur = first_action;
+ struct manager_action *cur;
char authority[80];
char *format = " %-15.15s %-15.15s %-55.55s\n";
@@ -529,7 +529,7 @@
ast_cli(fd, format, "------", "---------", "--------");
ast_mutex_lock(&actionlock);
- for (; cur; cur = cur->next) /* Walk the list of actions */
+ for (cur = first_action; cur; cur = cur->next) /* Walk the list of actions */
ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis);
ast_mutex_unlock(&actionlock);
@@ -1254,7 +1254,7 @@
static int action_listcommands(struct mansession *s, const struct message *m)
{
- struct manager_action *cur = first_action;
+ struct manager_action *cur;
char idText[256] = "";
char temp[BUFSIZ];
const char *id = astman_get_header(m,"ActionID");
@@ -1263,10 +1263,9 @@
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
astman_append(s, "Response: Success\r\n%s", idText);
ast_mutex_lock(&actionlock);
- while (cur) { /* Walk the list of actions */
+ for (cur = first_action; cur; cur = cur->next) {
if ((s->writeperm & cur->authority) == cur->authority)
astman_append(s, "%s: %s (Priv: %s)\r\n", cur->action, cur->synopsis, authority_to_str(cur->authority, temp, sizeof(temp)));
- cur = cur->next;
}
ast_mutex_unlock(&actionlock);
astman_append(s, "\r\n");
@@ -1958,7 +1957,7 @@
static int process_message(struct mansession *s, const struct message *m)
{
char action[80] = "";
- struct manager_action *tmp = first_action;
+ struct manager_action *tmp;
const char *id = astman_get_header(m,"ActionID");
char idText[256] = "";
int ret = 0;
@@ -2012,18 +2011,18 @@
} else
astman_send_error(s, m, "Authentication Required");
} else {
- while (tmp) {
- if (!strcasecmp(action, tmp->action)) {
- if ((s->writeperm & tmp->authority) == tmp->authority) {
- if (tmp->func(s, m))
- ret = -1;
- } else {
- astman_send_error(s, m, "Permission denied");
- }
- break;
- }
- tmp = tmp->next;
- }
+ ast_mutex_lock(&actionlock);
+ for (tmp = first_action; tmp; tmp = tmp->next) {
+ if (strcasecmp(action, tmp->action))
+ continue;
+ if ((s->writeperm & tmp->authority) == tmp->authority) {
+ if (tmp->func(s, m))
+ ret = -1;
+ } else
+ astman_send_error(s, m, "Permission denied");
+ break;
+ }
+ ast_mutex_unlock(&actionlock);
if (!tmp)
astman_send_error(s, m, "Invalid/unknown command");
}
@@ -2318,9 +2317,10 @@
int ast_manager_unregister(char *action)
{
- struct manager_action *cur = first_action, *prev = first_action;
+ struct manager_action *cur, *prev;
ast_mutex_lock(&actionlock);
+ cur = prev = first_action;
while (cur) {
if (!strcasecmp(action, cur->action)) {
prev->next = cur->next;
@@ -2346,10 +2346,11 @@
static int ast_manager_register_struct(struct manager_action *act)
{
- struct manager_action *cur = first_action, *prev = NULL;
+ struct manager_action *cur, *prev = NULL;
int ret;
ast_mutex_lock(&actionlock);
+ cur = first_action;
while (cur) { /* Walk the list of actions */
ret = strcasecmp(cur->action, act->action);
if (ret == 0) {
More information about the asterisk-commits
mailing list