[asterisk-dev] New manager command QueueSync - request for comments

Gabriel Ortiz Lour ortiz.admin at gmail.com
Tue Jan 11 14:08:00 CST 2011


Hi all,

  I've just finished testing a new function that I wrote that is kind of a
QueueAdd mixed with QueueRemove command.

  It receives a comma separated list of queue names and iterate over all the
queue. If the queuename being iterated is in the queuenames we received I
call the add_to_queue function, else I call the remove_from_queue function.

  The purpose of this email is to see if anyone would have any comments,
thoughts or remarks about my code, especially on the way I'm creating an
array using ast_calloc, strsep and ast_free.

  Follows the code. Thanks in advance.

Gabriel Ortiz





static int sync_to_queues(const char *queuenames, const char *interface,
const char *membername, int penalty, int paused, int dump, const char
*state_interface)
{
    int found, res = RES_OKAY, num_queues = 0, aux_count;
    struct call_queue *q;
    struct ao2_iterator queue_iter;
    char **queue_name = NULL, *buf;

    /* Make an array with the names of the queues we received */
    if (!ast_strlen_zero(queuenames)) {
        num_queues = 1;
        aux_count = 1;
        do {
            if (queuenames[aux_count] == ',') num_queues++;
        } while(queuenames[aux_count++] != '\0');

        aux_count = 0;
        queue_name = ast_calloc(num_queues, sizeof(char*));
        buf = ast_strdupa(queuenames);
        while ((queue_name[aux_count++] = strsep(&buf, ","))) {}
    }

    ao2_lock(queues);
    queue_iter = ao2_iterator_init(queues, 0);
    while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues for
memver Sync"))) {
        found = 0;
        if (num_queues > 0) {
            for(aux_count=0; aux_count<num_queues; aux_count++) {
                if(strcmp(queue_name[aux_count], q->name)) {
                    found = 1;
                    break;
                }
            }
        }

        res = (found) ?
                add_to_queue(q->name, interface, membername, penalty,
paused, dump, state_interface) :
                remove_from_queue(q->name, interface);

        if(res == RES_OUTOFMEMORY) {
            ast_log(LOG_WARNING, "Queue sync RES_OUTOFMEMORY when %s member
%s from queue %s\n", (found ? "adding" : "removing"), membername, q->name);
            break;
        }
    }
    ao2_iterator_destroy(&queue_iter);
    ao2_unlock(queues);

    if (num_queues > 0)
        ast_free(queue_name);

    return res;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20110111/63026cf2/attachment.htm>


More information about the asterisk-dev mailing list