--- asterisk_CVS/asterisk/apps/app_queue.c Sat Jul 17 21:58:00 2004 +++ asterisk/apps/app_queue.c Fri Jul 23 17:44:24 2004 @@ -7,6 +7,7 @@ * * Mark Spencer * + * 2004-07-23: Allow adding/removing interfaces via manager API (dw-asterisk@botanicus.net). * 2004-06-04: Priorities in queues added by inAccess Networks (work funded by Hellas On Line (HOL) www.hol.gr). * * These features added by David C. Troy : @@ -2062,6 +2063,146 @@ return RESULT_SUCCESS; } + + +/* Add a queue member. Expects headers "Queue:", and "Channel:". Optionally + "Penalty:" +*/ + +static int manager_queues_add(struct mansession *s, struct message *m ) +{ + char *queue_name, *interface, *penalty_s; + + int penalty = 0; + struct ast_call_queue *q; + struct member *new_member; + + queue_name = astman_get_header(m, "Queue"); + interface = astman_get_header(m, "Interface"); + penalty_s = astman_get_header(m, "Penalty"); + + + if (queue_name == NULL) { + astman_send_error(s, m, "'Queue' not specified."); + return 0; + } + + if (interface == NULL) { + astman_send_error(s, m, "'Interface' not specified."); + return 0; + } + + if (penalty_s == NULL) + penalty = 0; + else + penalty = strtoul(penalty_s, NULL, 10); + + + for (q = queues; q != NULL; q = q->next) { + ast_mutex_lock(&q->lock); + if (strcmp(q->name, queue_name) == 0) + break; + ast_mutex_unlock(&q->lock); + } + + if (q == NULL) { + astman_send_error(s, m, "Queue is not defined."); + return 0; + } + + if (interface_exists(q, interface) != NULL) { + astman_send_error(s, m, "Interface already exists."); + ast_mutex_unlock(&q->lock); + return 0; + } + + + new_member = create_queue_node(interface, penalty); + + if (new_member == NULL) { + astman_send_error(s, m, "Unable to add interface to queue."); + ast_mutex_unlock(&q->lock); + return 0; + } + + + new_member->next = q->members; + new_member->dynamic = 1; + q->members = new_member; + + ast_mutex_unlock(&q->lock); + ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", interface, queue_name); + astman_send_ack(s, m, "Interface added."); + return 0; +} + + + +/* + Remove a queue member, expects "Queue" and "Interface" headers. +*/ + +static int manager_queues_remove(struct mansession *s, struct message *m) +{ + char *queue_name, *interface; + struct member *node ; + struct member *look ; + struct ast_call_queue *q; + + queue_name = astman_get_header(m, "Queue"); + interface = astman_get_header(m, "Interface"); + + if (! (queue_name && interface)) { + astman_send_error(s, m, "Need 'Queue' and 'Interface' parameters."); + return 0; + } + + + for (q = queues; q != NULL; q = q->next) { + ast_mutex_lock(&q->lock); + if (strcmp(q->name, queue_name) == 0) + break; + ast_mutex_unlock(&q->lock); + } + + + if (q == NULL) { + astman_send_error(s, m, "Queue is not defined."); + return 0; + } + + if ((node = interface_exists(q, interface)) == NULL) { + astman_send_error(s, m, "Interface does not exist in queue."); + ast_mutex_unlock(&q->lock); + return 0; + } + + + if ((look = q->members) == node) + q->members = node->next; + else + while (look != NULL) { + if (look->next == node) { + look->next = node->next; + break; + } + else + look = look->next; + } + + free(node); + + ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", + interface, queue_name); + + + astman_send_ack(s, m, "Interface removed."); + ast_mutex_unlock(&q->lock); + return 0; +} + + + static char show_queues_usage[] = "Usage: show queues\n" " Provides summary information on call queues.\n"; @@ -2099,6 +2240,8 @@ ast_cli_register(&cli_show_queues); ast_manager_register( "Queues", 0, manager_queues_show, "Queues" ); ast_manager_register( "QueueStatus", 0, manager_queues_status, "Queue Status" ); + ast_manager_register( "QueueAdd", 0, manager_queues_add, "Add interface to queue." ); + ast_manager_register( "QueueRemove", 0, manager_queues_remove, "Remove interface from queue." ); // [PHM 06/26/03] ast_register_application(app_aqm, aqm_exec, app_aqm_synopsis, app_aqm_descrip) ;