Hi all,<br><br>  I&#39;ve just finished testing a new function that I wrote that is kind of a QueueAdd mixed with QueueRemove command.<br><br>  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.<br>
<br>  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&#39;m creating an array using ast_calloc, strsep and ast_free.<br><br>  Follows the code. Thanks in advance.<br>
<br>Gabriel Ortiz<br><br><br><br><br><br>static int sync_to_queues(const char *queuenames, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface)<br>{<br>    int found, res = RES_OKAY, num_queues = 0, aux_count;<br>
    struct call_queue *q;<br>    struct ao2_iterator queue_iter;<br>    char **queue_name = NULL, *buf;<br><br>    /* Make an array with the names of the queues we received */<br>    if (!ast_strlen_zero(queuenames)) {<br>
        num_queues = 1;<br>        aux_count = 1;<br>        do {<br>            if (queuenames[aux_count] == &#39;,&#39;) num_queues++;<br>        } while(queuenames[aux_count++] != &#39;\0&#39;);<br><br>        aux_count = 0;<br>
        queue_name = ast_calloc(num_queues, sizeof(char*));<br>        buf = ast_strdupa(queuenames);<br>        while ((queue_name[aux_count++] = strsep(&amp;buf, &quot;,&quot;))) {}<br>    }<br><br>    ao2_lock(queues);<br>
    queue_iter = ao2_iterator_init(queues, 0);<br>    while ((q = ao2_t_iterator_next(&amp;queue_iter, &quot;Iterate over queues for memver Sync&quot;))) {<br>        found = 0;<br>        if (num_queues &gt; 0) {<br>            for(aux_count=0; aux_count&lt;num_queues; aux_count++) {<br>
                if(strcmp(queue_name[aux_count], q-&gt;name)) {<br>                    found = 1;<br>                    break;<br>                }<br>            }<br>        }<br><br>        res = (found) ?<br>                add_to_queue(q-&gt;name, interface, membername, penalty, paused, dump, state_interface) :<br>
                remove_from_queue(q-&gt;name, interface);<br><br>        if(res == RES_OUTOFMEMORY) {<br>            ast_log(LOG_WARNING, &quot;Queue sync RES_OUTOFMEMORY when %s member %s from queue %s\n&quot;, (found ? &quot;adding&quot; : &quot;removing&quot;), membername, q-&gt;name);<br>
            break;<br>        }<br>    }<br>    ao2_iterator_destroy(&amp;queue_iter);<br>    ao2_unlock(queues);<br><br>    if (num_queues &gt; 0)<br>        ast_free(queue_name);<br><br>    return res;<br>}<br><br>