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

Mark Murawski markm-lists at intellasoft.net
Tue Jan 11 23:42:30 CST 2011


On 01/11/2011 03:08 PM, Gabriel Ortiz Lour wrote:
> 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;
> }
>
>
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
>     http://lists.digium.com/mailman/listinfo/asterisk-dev



Please also provide some examples of how this code would be used.



More information about the asterisk-dev mailing list