Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
app_queue.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2018, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief True call queues with optional send URL on answer
22 *
23 * \author Mark Spencer <markster@digium.com>
24 *
25 * \par Development notes
26 * \note 2004-11-25: Persistent Dynamic Members added by:
27 * NetNation Communications (www.netnation.com)
28 * Kevin Lindsay <kevinl@netnation.com>
29 *
30 * Each dynamic agent in each queue is now stored in the astdb.
31 * When asterisk is restarted, each agent will be automatically
32 * readded into their recorded queues. This feature can be
33 * configured with the 'persistent_members=<1|0>' setting in the
34 * '[general]' category in queues.conf. The default is on.
35 *
36 * \note 2004-06-04: Priorities in queues added by inAccess Networks (work funded by Hellas On Line (HOL) www.hol.gr).
37 *
38 * \note These features added by David C. Troy <dave@toad.net>:
39 * - Per-queue holdtime calculation
40 * - Estimated holdtime announcement
41 * - Position announcement
42 * - Abandoned/completed call counters
43 * - Failout timer passed as optional app parameter
44 *
45 * Patch Version 1.07 2003-12-24 01
46 *
47 * Added servicelevel statistic by Michiel Betel <michiel@betel.nl>
48 * Added Priority jumping code for adding and removing queue members by Jonathan Stanton <asterisk@doilooklikeicare.com>
49 *
50 * Fixed to work with CVS as of 2004-02-25 and released as 1.07a
51 * by Matthew Enger <m.enger@xi.com.au>
52 *
53 * \ingroup applications
54 */
55
56/*! \li \ref app_queues.c uses configuration file \ref queues.conf
57 * \addtogroup configuration_file
58 */
59
60/*! \page queues.conf queues.conf
61 * \verbinclude queues.conf.sample
62 */
63
64/*** MODULEINFO
65 <support_level>core</support_level>
66 ***/
67
68#include "asterisk.h"
69
70#include <sys/time.h>
71#include <signal.h>
72#include <netinet/in.h>
73#include <ctype.h>
74
75#include "asterisk/lock.h"
76#include "asterisk/file.h"
77#include "asterisk/channel.h"
78#include "asterisk/pbx.h"
79#include "asterisk/app.h"
81#include "asterisk/module.h"
82#include "asterisk/translate.h"
83#include "asterisk/say.h"
84#include "asterisk/features.h"
86#include "asterisk/cli.h"
87#include "asterisk/manager.h"
88#include "asterisk/config.h"
89#include "asterisk/utils.h"
90#include "asterisk/causes.h"
91#include "asterisk/astdb.h"
94#include "asterisk/astobj2.h"
95#include "asterisk/strings.h"
97#include "asterisk/aoc.h"
98#include "asterisk/callerid.h"
99#include "asterisk/term.h"
100#include "asterisk/dial.h"
105#include "asterisk/core_local.h"
106#include "asterisk/mixmonitor.h"
109
110/*!
111 * \par Please read before modifying this file.
112 * There are three locks which are regularly used
113 * throughout this file, the queue list lock, the lock
114 * for each individual queue, and the interface list lock.
115 * Please be extra careful to always lock in the following order
116 * 1) queue list lock
117 * 2) individual queue lock
118 * 3) interface list lock
119 * This order has sort of "evolved" over the lifetime of this
120 * application, but it is now in place this way, so please adhere
121 * to this order!
122 */
123
124/*** DOCUMENTATION
125 <application name="Queue" language="en_US">
126 <since>
127 <version>0.2.0</version>
128 </since>
129 <synopsis>
130 Queue a call for a call queue.
131 </synopsis>
132 <syntax>
133 <parameter name="queuename" required="true" />
134 <parameter name="options">
135 <optionlist>
136 <option name="b" argsep="^">
137 <para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
138 location using the newly created channel. The <literal>Gosub</literal> will be
139 executed for each destination channel.</para>
140 <argument name="context" required="false" />
141 <argument name="exten" required="false" />
142 <argument name="priority" required="true" hasparams="optional" argsep="^">
143 <argument name="arg1" multiple="true" required="true" />
144 <argument name="argN" />
145 </argument>
146 </option>
147 <option name="B" argsep="^">
148 <para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
149 specified location using the current channel.</para>
150 <argument name="context" required="false" />
151 <argument name="exten" required="false" />
152 <argument name="priority" required="true" hasparams="optional" argsep="^">
153 <argument name="arg1" multiple="true" required="true" />
154 <argument name="argN" />
155 </argument>
156 </option>
157 <option name="C">
158 <para>Mark all calls as "answered elsewhere" when cancelled.</para>
159 </option>
160 <option name="c">
161 <para>Continue in the dialplan if the callee hangs up.</para>
162 </option>
163 <option name="d">
164 <para>Data-quality (modem) call (minimum delay).</para>
165 <para>This option only applies to DAHDI channels. By default,
166 DTMF is verified by muting audio TX/RX to verify the tone
167 is still present. This option disables that behavior.</para>
168 </option>
169 <option name="F" argsep="^">
170 <argument name="context" required="false" />
171 <argument name="exten" required="false" />
172 <argument name="priority" required="true" />
173 <para>When the caller hangs up, transfer the <emphasis>called member</emphasis>
174 to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
175 <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
176 prefixed with one or two underbars ('_').</para>
177 <para>NOTE: Using this option from a Gosub() might not make sense as there would be no return points.</para>
178 </option>
179 <option name="h">
180 <para>Allow <emphasis>callee</emphasis> to hang up by pressing <literal>*</literal>.</para>
181 </option>
182 <option name="H">
183 <para>Allow <emphasis>caller</emphasis> to hang up by pressing <literal>*</literal>.</para>
184 </option>
185 <option name="i">
186 <para>Ignore call forward requests from queue members and do nothing
187 when they are requested.</para>
188 </option>
189 <option name="I">
190 <para>Asterisk will ignore any connected line update requests or any redirecting party
191 update requests it may receive on this dial attempt.</para>
192 </option>
193 <option name="k">
194 <para>Allow the <emphasis>called</emphasis> party to enable parking of the call by sending
195 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
196 </option>
197 <option name="K">
198 <para>Allow the <emphasis>calling</emphasis> party to enable parking of the call by sending
199 the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
200 </option>
201 <option name="m">
202 <para>Custom music on hold class to use, which will override the music on hold class configured
203 in <filename>queues.conf</filename>, if specified.</para>
204 <para>Note that CHANNEL(musicclass), if set, will still override this option.</para>
205 </option>
206 <option name="n">
207 <para>No retries on the timeout; will exit this application and
208 go to the next step.</para>
209 </option>
210 <option name="r">
211 <para>Ring instead of playing MOH. Periodic Announcements are still made, if applicable.</para>
212 </option>
213 <option name="R">
214 <para>Ring instead of playing MOH when a member channel is actually ringing.</para>
215 </option>
216 <option name="t">
217 <para>Allow the <emphasis>called</emphasis> user to transfer the calling user.</para>
218 </option>
219 <option name="T">
220 <para>Allow the <emphasis>calling</emphasis> user to transfer the call.</para>
221 </option>
222 <option name="x">
223 <para>Allow the <emphasis>called</emphasis> user to write the conversation
224 to disk via MixMonitor.</para>
225 </option>
226 <option name="X">
227 <para>Allow the <emphasis>calling</emphasis> user to write the conversation to
228 disk via MixMonitor.</para>
229 </option>
230 </optionlist>
231 </parameter>
232 <parameter name="URL">
233 <para><replaceable>URL</replaceable> will be sent to the called party if the channel supports it.</para>
234 </parameter>
235 <parameter name="announceoverride" argsep="&amp;">
236 <para>Announcement file(s) to play to agent before bridging
237 call, overriding the announcement(s) configured in
238 <filename>queues.conf</filename>, if any.</para>
239 <para>Ampersand separated list of filenames. If the filename
240 is a relative filename (it does not begin with a slash), it
241 will be searched for in the Asterisk sounds directory. If the
242 filename is able to be parsed as a URL, Asterisk will
243 download the file and then begin playback on it. To include a
244 literal <literal>&amp;</literal> in the URL you can enclose
245 the URL in single quotes.</para>
246 <argument name="announceoverride" required="true" />
247 <argument name="announceoverride2" multiple="true" />
248 </parameter>
249 <parameter name="timeout">
250 <para>Will cause the queue to fail out after a specified number of
251 seconds, checked between each <filename>queues.conf</filename> <replaceable>timeout</replaceable> and
252 <replaceable>retry</replaceable> cycle.</para>
253 </parameter>
254 <parameter name="AGI">
255 <para>Will setup an AGI script to be executed on the calling party's channel once they are
256 connected to a queue member.</para>
257 </parameter>
258 <parameter name="gosub">
259 <para>Will run a gosub on the called party's channel (the queue member)
260 once the parties are connected. The subroutine execution starts in the
261 named context at the s exten and priority 1.</para>
262 <note><para>Macro was removed in Asterisk 21 which resulted in an
263 argument ordering change. The upgrade notice was missed for this,
264 so a note is being made here to provide a record of the change
265 for users who have not upgraded yet.</para></note>
266 </parameter>
267 <parameter name="rule">
268 <para>Will cause the queue's defaultrule to be overridden by the rule specified.</para>
269 </parameter>
270 <parameter name="position">
271 <para>Attempt to enter the caller into the queue at the numerical position specified. <literal>1</literal>
272 would attempt to enter the caller at the head of the queue, and <literal>3</literal> would attempt to place
273 the caller third in the queue.</para>
274 </parameter>
275 </syntax>
276 <description>
277 <para>In addition to transferring the call, a call may be parked and then picked
278 up by another user.</para>
279 <para>This application will return to the dialplan if the queue does not exist, or
280 any of the join options cause the caller to not enter the queue.</para>
281 <para>This application does not automatically answer and should be preceded
282 by an application such as Answer(), Progress(), or Ringing().</para>
283 <para>This application sets the following channel variables upon completion:</para>
284 <variablelist>
285 <variable name="QUEUESTATUS">
286 <para>The status of the call as a text string.</para>
287 <value name="TIMEOUT" />
288 <value name="FULL" />
289 <value name="JOINEMPTY" />
290 <value name="LEAVEEMPTY" />
291 <value name="JOINUNAVAIL" />
292 <value name="LEAVEUNAVAIL" />
293 <value name="CONTINUE" />
294 <value name="WITHDRAW" />
295 </variable>
296 <variable name="ABANDONED">
297 <para>If the call was not answered by an agent this variable will be TRUE.</para>
298 <value name="TRUE" />
299 </variable>
300 <variable name="DIALEDPEERNUMBER">
301 <para>Resource of the agent that was dialed set on the outbound channel.</para>
302 </variable>
303 <variable name="QUEUE_WITHDRAW_INFO">
304 <para>If the call was successfully withdrawn from the queue, and the withdraw request was provided with optional withdraw info, the withdraw info will be stored in this variable.</para>
305 </variable>
306 </variablelist>
307 </description>
308 <see-also>
309 <ref type="application">Queue</ref>
310 <ref type="application">QueueLog</ref>
311 <ref type="application">AddQueueMember</ref>
312 <ref type="application">RemoveQueueMember</ref>
313 <ref type="application">PauseQueueMember</ref>
314 <ref type="application">UnpauseQueueMember</ref>
315 <ref type="function">QUEUE_VARIABLES</ref>
316 <ref type="function">QUEUE_MEMBER</ref>
317 <ref type="function">QUEUE_EXISTS</ref>
318 <ref type="function">QUEUE_GET_CHANNEL</ref>
319 <ref type="function">QUEUE_WAITING_COUNT</ref>
320 <ref type="function">QUEUE_MEMBER_LIST</ref>
321 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
322 </see-also>
323 </application>
324 <application name="AddQueueMember" language="en_US">
325 <since>
326 <version>0.5.0</version>
327 </since>
328 <synopsis>
329 Dynamically adds queue members.
330 </synopsis>
331 <syntax>
332 <parameter name="queuename" required="true" />
333 <parameter name="interface" />
334 <parameter name="penalty" />
335 <parameter name="options">
336 <optionlist>
337 <option name="p">
338 <para>Add queue member in paused state.</para>
339 </option>
340 <option name="r">
341 <argument name="reason" required="true" />
342 <para>Specify a reason why the member is in paused state.</para>
343 </option>
344 </optionlist>
345 </parameter>
346 <parameter name="membername" />
347 <parameter name="stateinterface" />
348 <parameter name="wrapuptime" />
349 </syntax>
350 <description>
351 <para>Dynamically adds interface to an existing queue. If the interface is
352 already in the queue it will return an error.</para>
353 <para>This application sets the following channel variable upon completion:</para>
354 <variablelist>
355 <variable name="AQMSTATUS">
356 <para>The status of the attempt to add a queue member as a text string.</para>
357 <value name="ADDED" />
358 <value name="MEMBERALREADY" />
359 <value name="NOSUCHQUEUE" />
360 </variable>
361 </variablelist>
362 </description>
363 <see-also>
364 <ref type="application">Queue</ref>
365 <ref type="application">QueueLog</ref>
366 <ref type="application">AddQueueMember</ref>
367 <ref type="application">RemoveQueueMember</ref>
368 <ref type="application">PauseQueueMember</ref>
369 <ref type="application">UnpauseQueueMember</ref>
370 <ref type="function">QUEUE_VARIABLES</ref>
371 <ref type="function">QUEUE_MEMBER</ref>
372 <ref type="function">QUEUE_EXISTS</ref>
373 <ref type="function">QUEUE_GET_CHANNEL</ref>
374 <ref type="function">QUEUE_WAITING_COUNT</ref>
375 <ref type="function">QUEUE_MEMBER_LIST</ref>
376 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
377 </see-also>
378 </application>
379 <application name="RemoveQueueMember" language="en_US">
380 <since>
381 <version>0.5.0</version>
382 </since>
383 <synopsis>
384 Dynamically removes queue members.
385 </synopsis>
386 <syntax>
387 <parameter name="queuename" required="true" />
388 <parameter name="interface" />
389 </syntax>
390 <description>
391 <para>If the interface is <emphasis>NOT</emphasis> in the queue it will return an error.</para>
392 <para>This application sets the following channel variable upon completion:</para>
393 <variablelist>
394 <variable name="RQMSTATUS">
395 <value name="REMOVED" />
396 <value name="NOTINQUEUE" />
397 <value name="NOSUCHQUEUE" />
398 <value name="NOTDYNAMIC" />
399 </variable>
400 </variablelist>
401 <example title="Remove queue member">
402 same => n,RemoveQueueMember(techsupport,SIP/3000)
403 </example>
404 </description>
405 <see-also>
406 <ref type="application">Queue</ref>
407 <ref type="application">QueueLog</ref>
408 <ref type="application">AddQueueMember</ref>
409 <ref type="application">RemoveQueueMember</ref>
410 <ref type="application">PauseQueueMember</ref>
411 <ref type="application">UnpauseQueueMember</ref>
412 <ref type="function">QUEUE_VARIABLES</ref>
413 <ref type="function">QUEUE_MEMBER</ref>
414 <ref type="function">QUEUE_EXISTS</ref>
415 <ref type="function">QUEUE_GET_CHANNEL</ref>
416 <ref type="function">QUEUE_WAITING_COUNT</ref>
417 <ref type="function">QUEUE_MEMBER_LIST</ref>
418 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
419 </see-also>
420 </application>
421 <application name="PauseQueueMember" language="en_US">
422 <since>
423 <version>1.2.0</version>
424 </since>
425 <synopsis>
426 Pauses a queue member.
427 </synopsis>
428 <syntax>
429 <parameter name="queuename" />
430 <parameter name="interface" required="true" />
431 <parameter name="options" />
432 <parameter name="reason">
433 <para>Is used to add extra information to the appropriate queue_log entries and manager events.</para>
434 </parameter>
435 </syntax>
436 <description>
437 <para>Pauses (blocks calls for) a queue member. The given interface will be paused in the given queue.
438 This prevents any calls from being sent from the queue to the interface until it is
439 unpaused with UnpauseQueueMember or the manager interface. If no queuename is given,
440 the interface is paused in every queue it is a member of. The application will fail if the
441 interface is not found.</para>
442 <para>This application sets the following channel variable upon completion:</para>
443 <variablelist>
444 <variable name="PQMSTATUS">
445 <para>The status of the attempt to pause a queue member as a text string.</para>
446 <value name="PAUSED" />
447 <value name="NOTFOUND" />
448 </variable>
449 </variablelist>
450 <example title="Pause queue member">
451 same => n,PauseQueueMember(,SIP/3000)
452 </example>
453 </description>
454 <see-also>
455 <ref type="application">Queue</ref>
456 <ref type="application">QueueLog</ref>
457 <ref type="application">AddQueueMember</ref>
458 <ref type="application">RemoveQueueMember</ref>
459 <ref type="application">PauseQueueMember</ref>
460 <ref type="application">UnpauseQueueMember</ref>
461 <ref type="function">QUEUE_VARIABLES</ref>
462 <ref type="function">QUEUE_MEMBER</ref>
463 <ref type="function">QUEUE_EXISTS</ref>
464 <ref type="function">QUEUE_GET_CHANNEL</ref>
465 <ref type="function">QUEUE_WAITING_COUNT</ref>
466 <ref type="function">QUEUE_MEMBER_LIST</ref>
467 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
468 </see-also>
469 </application>
470 <application name="UnpauseQueueMember" language="en_US">
471 <since>
472 <version>1.2.0</version>
473 </since>
474 <synopsis>
475 Unpauses a queue member.
476 </synopsis>
477 <syntax>
478 <parameter name="queuename" />
479 <parameter name="interface" required="true" />
480 <parameter name="options" />
481 <parameter name="reason">
482 <para>Is used to add extra information to the appropriate queue_log entries and manager events.</para>
483 </parameter>
484 </syntax>
485 <description>
486 <para>Unpauses (resumes calls to) a queue member. This is the counterpart to <literal>PauseQueueMember()</literal>
487 and operates exactly the same way, except it unpauses instead of pausing the given interface.</para>
488 <para>This application sets the following channel variable upon completion:</para>
489 <variablelist>
490 <variable name="UPQMSTATUS">
491 <para>The status of the attempt to unpause a queue member as a text string.</para>
492 <value name="UNPAUSED" />
493 <value name="NOTFOUND" />
494 </variable>
495 </variablelist>
496 <example title="Unpause queue member">
497 same => n,UnpauseQueueMember(,SIP/3000)
498 </example>
499 </description>
500 <see-also>
501 <ref type="application">Queue</ref>
502 <ref type="application">QueueLog</ref>
503 <ref type="application">AddQueueMember</ref>
504 <ref type="application">RemoveQueueMember</ref>
505 <ref type="application">PauseQueueMember</ref>
506 <ref type="application">UnpauseQueueMember</ref>
507 <ref type="function">QUEUE_VARIABLES</ref>
508 <ref type="function">QUEUE_MEMBER</ref>
509 <ref type="function">QUEUE_EXISTS</ref>
510 <ref type="function">QUEUE_GET_CHANNEL</ref>
511 <ref type="function">QUEUE_WAITING_COUNT</ref>
512 <ref type="function">QUEUE_MEMBER_LIST</ref>
513 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
514 </see-also>
515 </application>
516 <application name="QueueLog" language="en_US">
517 <since>
518 <version>1.4.0</version>
519 </since>
520 <synopsis>
521 Writes to the queue_log file.
522 </synopsis>
523 <syntax>
524 <parameter name="queuename" required="true" />
525 <parameter name="uniqueid" required="true" />
526 <parameter name="agent" required="true" />
527 <parameter name="event" required="true" />
528 <parameter name="additionalinfo" />
529 </syntax>
530 <description>
531 <para>Allows you to write your own events into the queue log.</para>
532 <example title="Log custom queue event">
533 same => n,QueueLog(101,${UNIQUEID},${AGENT},WENTONBREAK,600)
534 </example>
535 </description>
536 <see-also>
537 <ref type="application">Queue</ref>
538 <ref type="application">QueueLog</ref>
539 <ref type="application">AddQueueMember</ref>
540 <ref type="application">RemoveQueueMember</ref>
541 <ref type="application">PauseQueueMember</ref>
542 <ref type="application">UnpauseQueueMember</ref>
543 <ref type="function">QUEUE_VARIABLES</ref>
544 <ref type="function">QUEUE_MEMBER</ref>
545 <ref type="function">QUEUE_EXISTS</ref>
546 <ref type="function">QUEUE_GET_CHANNEL</ref>
547 <ref type="function">QUEUE_WAITING_COUNT</ref>
548 <ref type="function">QUEUE_MEMBER_LIST</ref>
549 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
550 </see-also>
551 </application>
552 <application name="QueueUpdate" language="en_US">
553 <since>
554 <version>15.0.0</version>
555 </since>
556 <synopsis>
557 Writes to the queue_log file for outbound calls and updates Realtime Data.
558 Is used at h extension to be able to have all the parameters.
559 </synopsis>
560 <syntax>
561 <parameter name="queuename" required="true" />
562 <parameter name="uniqueid" required="true" />
563 <parameter name="agent" required="true" />
564 <parameter name="status" required="true" />
565 <parameter name="talktime" required="true" />
566 <parameter name="params" required="false" />
567 </syntax>
568 <description>
569 <para>Allows you to write Outbound events into the queue log.</para>
570 <example title="Write outbound event into queue log">
571 exten => h,1,QueueUpdate(${QUEUE}, ${UNIQUEID}, ${AGENT}, ${DIALSTATUS}, ${ANSWEREDTIME}, ${DIALEDTIME} | ${DIALEDNUMBER})
572 </example>
573 </description>
574 </application>
575 <function name="QUEUE_VARIABLES" language="en_US">
576 <since>
577 <version>1.6.0</version>
578 </since>
579 <synopsis>
580 Return Queue information in variables.
581 </synopsis>
582 <syntax>
583 <parameter name="queuename" required="true">
584 <enumlist>
585 <enum name="QUEUEMAX">
586 <para>Maximum number of calls allowed.</para>
587 </enum>
588 <enum name="QUEUESTRATEGY">
589 <para>The strategy of the queue.</para>
590 </enum>
591 <enum name="QUEUECALLS">
592 <para>Number of calls currently in the queue.</para>
593 </enum>
594 <enum name="QUEUEHOLDTIME">
595 <para>Current average hold time.</para>
596 </enum>
597 <enum name="QUEUECOMPLETED">
598 <para>Number of completed calls for the queue.</para>
599 </enum>
600 <enum name="QUEUEABANDONED">
601 <para>Number of abandoned calls.</para>
602 </enum>
603 <enum name="QUEUESRVLEVEL">
604 <para>Queue service level.</para>
605 </enum>
606 <enum name="QUEUESRVLEVELPERF">
607 <para>Current service level performance.</para>
608 </enum>
609 </enumlist>
610 </parameter>
611 </syntax>
612 <description>
613 <para>Makes the following queue variables available.</para>
614 <para>Returns <literal>0</literal> if queue is found and setqueuevar is defined, <literal>-1</literal> otherwise.</para>
615 </description>
616 <see-also>
617 <ref type="application">Queue</ref>
618 <ref type="application">QueueLog</ref>
619 <ref type="application">AddQueueMember</ref>
620 <ref type="application">RemoveQueueMember</ref>
621 <ref type="application">PauseQueueMember</ref>
622 <ref type="application">UnpauseQueueMember</ref>
623 <ref type="function">QUEUE_VARIABLES</ref>
624 <ref type="function">QUEUE_MEMBER</ref>
625 <ref type="function">QUEUE_EXISTS</ref>
626 <ref type="function">QUEUE_GET_CHANNEL</ref>
627 <ref type="function">QUEUE_WAITING_COUNT</ref>
628 <ref type="function">QUEUE_MEMBER_LIST</ref>
629 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
630 </see-also>
631 </function>
632 <function name="QUEUE_MEMBER" language="en_US">
633 <since>
634 <version>1.6.0</version>
635 </since>
636 <synopsis>
637 Provides a count of queue members based on the provided criteria, or updates a
638 queue member's settings.
639 </synopsis>
640 <syntax>
641 <parameter name="queuename" required="false" />
642 <parameter name="option" required="true">
643 <enumlist>
644 <enum name="logged">
645 <para>Returns the number of logged-in members for the specified queue.</para>
646 </enum>
647 <enum name="free">
648 <para>Returns the number of logged-in members for the specified queue that either can take calls or are currently wrapping up after a previous call.</para>
649 </enum>
650 <enum name="ready">
651 <para>Returns the number of logged-in members for the specified queue that are immediately available to answer a call.</para>
652 </enum>
653 <enum name="count">
654 <para>Returns the total number of members for the specified queue.</para>
655 </enum>
656 <enum name="penalty">
657 <para>Gets or sets queue member penalty. If
658 <replaceable>queuename</replaceable> is not specified
659 when setting the penalty then the penalty is set in all queues
660 the interface is a member.</para>
661 </enum>
662 <enum name="paused">
663 <para>Gets or sets queue member paused status. If
664 <replaceable>queuename</replaceable> is not specified
665 when setting the paused status then the paused status is set
666 in all queues the interface is a member.</para>
667 </enum>
668 <enum name="ringinuse">
669 <para>Gets or sets queue member ringinuse. If
670 <replaceable>queuename</replaceable> is not specified
671 when setting ringinuse then ringinuse is set
672 in all queues the interface is a member.</para>
673 </enum>
674 </enumlist>
675 </parameter>
676 <parameter name="interface" required="false" />
677 </syntax>
678 <description>
679 <para>Allows access to queue counts [R] and member information [R/W].</para>
680 <para><replaceable>queuename</replaceable> is required for all read operations.</para>
681 <para><replaceable>interface</replaceable> is required for all member operations.</para>
682 </description>
683 <see-also>
684 <ref type="application">Queue</ref>
685 <ref type="application">QueueLog</ref>
686 <ref type="application">AddQueueMember</ref>
687 <ref type="application">RemoveQueueMember</ref>
688 <ref type="application">PauseQueueMember</ref>
689 <ref type="application">UnpauseQueueMember</ref>
690 <ref type="function">QUEUE_VARIABLES</ref>
691 <ref type="function">QUEUE_MEMBER</ref>
692 <ref type="function">QUEUE_EXISTS</ref>
693 <ref type="function">QUEUE_GET_CHANNEL</ref>
694 <ref type="function">QUEUE_WAITING_COUNT</ref>
695 <ref type="function">QUEUE_MEMBER_LIST</ref>
696 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
697 </see-also>
698 </function>
699 <function name="QUEUE_EXISTS" language="en_US">
700 <since>
701 <version>1.8.0</version>
702 </since>
703 <synopsis>
704 Check if a named queue exists on this server
705 </synopsis>
706 <syntax>
707 <parameter name="queuename" />
708 </syntax>
709 <description>
710 <para>Returns 1 if the specified queue exists, 0 if it does not</para>
711 </description>
712 <see-also>
713 <ref type="application">Queue</ref>
714 <ref type="application">QueueLog</ref>
715 <ref type="application">AddQueueMember</ref>
716 <ref type="application">RemoveQueueMember</ref>
717 <ref type="application">PauseQueueMember</ref>
718 <ref type="application">UnpauseQueueMember</ref>
719 <ref type="function">QUEUE_VARIABLES</ref>
720 <ref type="function">QUEUE_MEMBER</ref>
721 <ref type="function">QUEUE_EXISTS</ref>
722 <ref type="function">QUEUE_GET_CHANNEL</ref>
723 <ref type="function">QUEUE_WAITING_COUNT</ref>
724 <ref type="function">QUEUE_MEMBER_LIST</ref>
725 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
726 </see-also>
727 </function>
728 <function name="QUEUE_GET_CHANNEL" language="en_US">
729 <since>
730 <version>14.0.0</version>
731 </since>
732 <synopsis>
733 Return caller at the specified position in a queue.
734 </synopsis>
735 <syntax>
736 <parameter name="queuename" required="true" />
737 <parameter name="position" />
738 </syntax>
739 <description>
740 <para>Returns the caller channel at <replaceable>position</replaceable> in the specified <replaceable>queuename</replaceable>.</para>
741 <para>If <replaceable>position</replaceable> is unspecified the first channel is returned.</para>
742 </description>
743 <see-also>
744 <ref type="application">Queue</ref>
745 <ref type="application">QueueLog</ref>
746 <ref type="application">AddQueueMember</ref>
747 <ref type="application">RemoveQueueMember</ref>
748 <ref type="application">PauseQueueMember</ref>
749 <ref type="application">UnpauseQueueMember</ref>
750 <ref type="function">QUEUE_VARIABLES</ref>
751 <ref type="function">QUEUE_MEMBER</ref>
752 <ref type="function">QUEUE_EXISTS</ref>
753 <ref type="function">QUEUE_WAITING_COUNT</ref>
754 <ref type="function">QUEUE_MEMBER_LIST</ref>
755 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
756 </see-also>
757 </function>
758 <function name="QUEUE_WAITING_COUNT" language="en_US">
759 <since>
760 <version>1.4.0</version>
761 </since>
762 <synopsis>
763 Count number of calls currently waiting in a queue.
764 </synopsis>
765 <syntax>
766 <parameter name="queuename" />
767 </syntax>
768 <description>
769 <para>Returns the number of callers currently waiting in the specified <replaceable>queuename</replaceable>.</para>
770 </description>
771 <see-also>
772 <ref type="application">Queue</ref>
773 <ref type="application">QueueLog</ref>
774 <ref type="application">AddQueueMember</ref>
775 <ref type="application">RemoveQueueMember</ref>
776 <ref type="application">PauseQueueMember</ref>
777 <ref type="application">UnpauseQueueMember</ref>
778 <ref type="function">QUEUE_VARIABLES</ref>
779 <ref type="function">QUEUE_MEMBER</ref>
780 <ref type="function">QUEUE_EXISTS</ref>
781 <ref type="function">QUEUE_GET_CHANNEL</ref>
782 <ref type="function">QUEUE_WAITING_COUNT</ref>
783 <ref type="function">QUEUE_MEMBER_LIST</ref>
784 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
785 </see-also>
786 </function>
787 <function name="QUEUE_MEMBER_LIST" language="en_US">
788 <since>
789 <version>1.4.0</version>
790 </since>
791 <synopsis>
792 Returns a list of interfaces on a queue.
793 </synopsis>
794 <syntax>
795 <parameter name="queuename" required="true" />
796 </syntax>
797 <description>
798 <para>Returns a comma-separated list of members associated with the specified <replaceable>queuename</replaceable>.</para>
799 </description>
800 <see-also>
801 <ref type="application">Queue</ref>
802 <ref type="application">QueueLog</ref>
803 <ref type="application">AddQueueMember</ref>
804 <ref type="application">RemoveQueueMember</ref>
805 <ref type="application">PauseQueueMember</ref>
806 <ref type="application">UnpauseQueueMember</ref>
807 <ref type="function">QUEUE_VARIABLES</ref>
808 <ref type="function">QUEUE_MEMBER</ref>
809 <ref type="function">QUEUE_EXISTS</ref>
810 <ref type="function">QUEUE_GET_CHANNEL</ref>
811 <ref type="function">QUEUE_WAITING_COUNT</ref>
812 <ref type="function">QUEUE_MEMBER_LIST</ref>
813 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
814 </see-also>
815 </function>
816 <function name="QUEUE_MEMBER_PENALTY" language="en_US">
817 <since>
818 <version>1.6.0</version>
819 </since>
820 <synopsis>
821 Gets or sets queue members penalty.
822 </synopsis>
823 <syntax>
824 <parameter name="queuename" required="true" />
825 <parameter name="interface" required="true" />
826 </syntax>
827 <description>
828 <para>Gets or sets queue members penalty.</para>
829 <warning><para>This function has been deprecated in favor of the <literal>QUEUE_MEMBER()</literal> function</para></warning>
830 </description>
831 <see-also>
832 <ref type="application">Queue</ref>
833 <ref type="application">QueueLog</ref>
834 <ref type="application">AddQueueMember</ref>
835 <ref type="application">RemoveQueueMember</ref>
836 <ref type="application">PauseQueueMember</ref>
837 <ref type="application">UnpauseQueueMember</ref>
838 <ref type="function">QUEUE_VARIABLES</ref>
839 <ref type="function">QUEUE_MEMBER</ref>
840 <ref type="function">QUEUE_EXISTS</ref>
841 <ref type="function">QUEUE_GET_CHANNEL</ref>
842 <ref type="function">QUEUE_WAITING_COUNT</ref>
843 <ref type="function">QUEUE_MEMBER_LIST</ref>
844 <ref type="function">QUEUE_MEMBER_PENALTY</ref>
845 </see-also>
846 </function>
847 <manager name="QueueStatus" language="en_US">
848 <since>
849 <version>0.5.0</version>
850 </since>
851 <synopsis>
852 Show queue status.
853 </synopsis>
854 <syntax>
855 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
856 <parameter name="Queue">
857 <para>Limit the response to the status of the specified queue.</para>
858 </parameter>
859 <parameter name="Member">
860 <para>Limit the response to the status of the specified member.</para>
861 </parameter>
862 </syntax>
863 <description>
864 <para>Check the status of one or more queues.</para>
865 </description>
866 </manager>
867 <manager name="QueueSummary" language="en_US">
868 <since>
869 <version>1.6.0</version>
870 </since>
871 <synopsis>
872 Show queue summary.
873 </synopsis>
874 <syntax>
875 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
876 <parameter name="Queue">
877 <para>Queue for which the summary is requested.</para>
878 </parameter>
879 </syntax>
880 <description>
881 <para>Request the manager to send a QueueSummary event.</para>
882 </description>
883 </manager>
884 <manager name="QueueAdd" language="en_US">
885 <since>
886 <version>1.0.0</version>
887 </since>
888 <synopsis>
889 Add interface to queue.
890 </synopsis>
891 <syntax>
892 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
893 <parameter name="Queue" required="true">
894 <para>Queue's name.</para>
895 </parameter>
896 <parameter name="Interface" required="true">
897 <para>The name of the interface (tech/name) to add to the queue.</para>
898 </parameter>
899 <parameter name="Penalty">
900 <para>A penalty (number) to apply to this member. Asterisk will distribute calls to members with higher penalties only after attempting to distribute calls to those with lower penalty.</para>
901 </parameter>
902 <parameter name="Paused">
903 <para>To pause or not the member initially (true/false or 1/0).</para>
904 </parameter>
905 <parameter name="Reason" required="false">
906 <para>Text description why the member is paused.</para>
907 </parameter>
908 <parameter name="MemberName">
909 <para>Text alias for the interface.</para>
910 </parameter>
911 <parameter name="StateInterface" />
912 </syntax>
913 <description>
914 </description>
915 </manager>
916 <manager name="QueueRemove" language="en_US">
917 <since>
918 <version>1.0.0</version>
919 </since>
920 <synopsis>
921 Remove interface from queue.
922 </synopsis>
923 <syntax>
924 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
925 <parameter name="Queue" required="true">
926 <para>The name of the queue to take action on.</para>
927 </parameter>
928 <parameter name="Interface" required="true">
929 <para>The interface (tech/name) to remove from queue.</para>
930 </parameter>
931 </syntax>
932 <description>
933 </description>
934 </manager>
935 <manager name="QueuePause" language="en_US">
936 <since>
937 <version>1.2.0</version>
938 </since>
939 <synopsis>
940 Makes a queue member temporarily unavailable.
941 </synopsis>
942 <syntax>
943 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
944 <parameter name="Interface" required="true">
945 <para>The name of the interface (tech/name) to pause or unpause.</para>
946 </parameter>
947 <parameter name="Paused" required="true">
948 <para>Pause or unpause the interface. Set to 'true' to pause the member or 'false' to unpause.</para>
949 </parameter>
950 <parameter name="Queue" required="false">
951 <para>The name of the queue in which to pause or unpause this member. If not specified, the member will be paused or unpaused in all the queues it is a member of.</para>
952 </parameter>
953 <parameter name="Reason" required="false">
954 <para>Text description, returned in the event QueueMemberPaused.</para>
955 </parameter>
956 </syntax>
957 <description>
958 <para>Pause or unpause a member in a queue.</para>
959 </description>
960 </manager>
961 <manager name="QueueLog" language="en_US">
962 <since>
963 <version>1.6.0</version>
964 </since>
965 <synopsis>
966 Adds custom entry in queue_log.
967 </synopsis>
968 <syntax>
969 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
970 <parameter name="Queue" required="true" />
971 <parameter name="Event" required="true" />
972 <parameter name="Uniqueid" />
973 <parameter name="Interface" />
974 <parameter name="Message" />
975 </syntax>
976 <description>
977 </description>
978 </manager>
979 <manager name="QueuePenalty" language="en_US">
980 <since>
981 <version>1.6.0</version>
982 </since>
983 <synopsis>
984 Set the penalty for a queue member.
985 </synopsis>
986 <syntax>
987 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
988 <parameter name="Interface" required="true">
989 <para>The interface (tech/name) of the member whose penalty to change.</para>
990 </parameter>
991 <parameter name="Penalty" required="true">
992 <para>The new penalty (number) for the member. Must be nonnegative.</para>
993 </parameter>
994 <parameter name="Queue">
995 <para>If specified, only set the penalty for the member of this queue. Otherwise, set the penalty for the member in all queues to which the member belongs.</para>
996 </parameter>
997 </syntax>
998 <description>
999 <para>Change the penalty of a queue member</para>
1000 </description>
1001 </manager>
1002 <manager name="QueueMemberRingInUse" language="en_US">
1003 <since>
1004 <version>11.0.0</version>
1005 </since>
1006 <synopsis>
1007 Set the ringinuse value for a queue member.
1008 </synopsis>
1009 <syntax>
1010 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1011 <parameter name="Interface" required="true" />
1012 <parameter name="RingInUse" required="true" />
1013 <parameter name="Queue" />
1014 </syntax>
1015 <description>
1016 </description>
1017 </manager>
1018 <manager name="QueueRule" language="en_US">
1019 <since>
1020 <version>1.6.0</version>
1021 </since>
1022 <synopsis>
1023 Queue Rules.
1024 </synopsis>
1025 <syntax>
1026 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1027 <parameter name="Rule">
1028 <para>The name of the rule in queuerules.conf whose contents to list.</para>
1029 </parameter>
1030 </syntax>
1031 <description>
1032 <para>List queue rules defined in queuerules.conf</para>
1033 </description>
1034 </manager>
1035 <manager name="QueueReload" language="en_US">
1036 <since>
1037 <version>1.6.2.0</version>
1038 </since>
1039 <synopsis>
1040 Reload a queue, queues, or any sub-section of a queue or queues.
1041 </synopsis>
1042 <syntax>
1043 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1044 <parameter name="Queue">
1045 <para>The name of the queue to take action on. If no queue name is specified, then all queues are affected.</para>
1046 </parameter>
1047 <parameter name="Members">
1048 <para>Whether to reload the queue's members.</para>
1049 <enumlist>
1050 <enum name="yes" />
1051 <enum name="no" />
1052 </enumlist>
1053 </parameter>
1054 <parameter name="Rules">
1055 <para>Whether to reload queuerules.conf</para>
1056 <enumlist>
1057 <enum name="yes" />
1058 <enum name="no" />
1059 </enumlist>
1060 </parameter>
1061 <parameter name="Parameters">
1062 <para>Whether to reload the other queue options.</para>
1063 <enumlist>
1064 <enum name="yes" />
1065 <enum name="no" />
1066 </enumlist>
1067 </parameter>
1068 </syntax>
1069 <description>
1070 </description>
1071 </manager>
1072 <manager name="QueueReset" language="en_US">
1073 <since>
1074 <version>1.6.2.0</version>
1075 </since>
1076 <synopsis>
1077 Reset queue statistics.
1078 </synopsis>
1079 <syntax>
1080 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1081 <parameter name="Queue">
1082 <para>The name of the queue on which to reset statistics.</para>
1083 </parameter>
1084 </syntax>
1085 <description>
1086 <para>Reset the statistics for a queue.</para>
1087 </description>
1088 </manager>
1089 <manager name="QueueChangePriorityCaller" language="en_US">
1090 <since>
1091 <version>15.0.0</version>
1092 </since>
1093 <synopsis>
1094 Change priority of a caller on queue.
1095 </synopsis>
1096 <syntax>
1097 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1098 <parameter name="Queue" required="true">
1099 <para>The name of the queue to take action on.</para>
1100 </parameter>
1101 <parameter name="Caller" required="true">
1102 <para>The caller (channel) to change priority on queue.</para>
1103 </parameter>
1104
1105 <parameter name="Priority" required="true">
1106 <para>Priority value for change for caller on queue.</para>
1107 </parameter>
1108 <parameter name="Immediate">
1109 <para>When set to yes will cause the priority change to be reflected immediately, causing the channel to change position within the queue.</para>
1110 </parameter>
1111 </syntax>
1112 <description>
1113 </description>
1114 </manager>
1115 <manager name="QueueWithdrawCaller" language="en_US">
1116 <since>
1117 <version>19.3.0</version>
1118 <version>18.11.0</version>
1119 <version>16.25.0</version>
1120 </since>
1121 <synopsis>
1122 Request to withdraw a caller from the queue back to the dialplan.
1123 </synopsis>
1124 <syntax>
1125 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
1126 <parameter name="Queue" required="true">
1127 <para>The name of the queue to take action on.</para>
1128 </parameter>
1129 <parameter name="Caller" required="true">
1130 <para>The caller (channel) to withdraw from the queue.</para>
1131 </parameter>
1132 <parameter name="WithdrawInfo" required="false">
1133 <para>Optional info to store. If the call is successfully withdrawn from the queue, this information will be available in the QUEUE_WITHDRAW_INFO variable.</para>
1134 </parameter>
1135 </syntax>
1136 <description>
1137 </description>
1138 </manager>
1139
1140 <managerEvent language="en_US" name="QueueParams">
1141 <managerEventInstance class="EVENT_FLAG_AGENT">
1142 <since>
1143 <version>16.24.0</version>
1144 <version>18.10.0</version>
1145 <version>19.2.0</version>
1146 </since>
1147 <synopsis>Raised in response to the QueueStatus action.</synopsis>
1148 <syntax>
1149 <parameter name="Max">
1150 <para>The name of the queue.</para>
1151 </parameter>
1152 <parameter name="Strategy">
1153 <para>The strategy of the queue.</para>
1154 </parameter>
1155 <parameter name="Calls">
1156 <para>The queue member's channel technology or location.</para>
1157 </parameter>
1158 <parameter name="Holdtime">
1159 <para>The queue's hold time.</para>
1160 </parameter>
1161 <parameter name="TalkTime">
1162 <para>The queue's talk time.</para>
1163 </parameter>
1164 <parameter name="Completed">
1165 <para>The queue's completion time.</para>
1166 </parameter>
1167 <parameter name="Abandoned">
1168 <para>The queue's call abandonment metric.</para>
1169 </parameter>
1170 <parameter name="ServiceLevelPerf">
1171 <para>Primary service level performance metric.</para>
1172 </parameter>
1173 <parameter name="ServiceLevelPerf2">
1174 <para>Secondary service level performance metric.</para>
1175 </parameter>
1176 </syntax>
1177 <see-also>
1178 <ref type="managerEvent">QueueMember</ref>
1179 <ref type="managerEvent">QueueEntry</ref>
1180 </see-also>
1181 </managerEventInstance>
1182 </managerEvent>
1183 <managerEvent language="en_US" name="QueueEntry">
1184 <managerEventInstance class="EVENT_FLAG_AGENT">
1185 <since>
1186 <version>16.24.0</version>
1187 <version>18.10.0</version>
1188 <version>19.2.0</version>
1189 </since>
1190 <synopsis>Raised in response to the QueueStatus action.</synopsis>
1191 <syntax>
1192 <parameter name="Queue">
1193 <para>The name of the queue.</para>
1194 </parameter>
1195 <parameter name="Position">
1196 <para>The caller's position within the queue.</para>
1197 </parameter>
1198 <parameter name="Channel">
1199 <para>The name of the caller's channel.</para>
1200 </parameter>
1201 <parameter name="Uniqueid">
1202 <para>The unique ID of the channel.</para>
1203 </parameter>
1204 <parameter name="CallerIDNum">
1205 <para>The Caller ID number.</para>
1206 </parameter>
1207 <parameter name="CallerIDName">
1208 <para>The Caller ID name.</para>
1209 </parameter>
1210 <parameter name="ConnectedLineNum">
1211 <para>The bridged party's number.</para>
1212 </parameter>
1213 <parameter name="ConnectedLineName">
1214 <para>The bridged party's name.</para>
1215 </parameter>
1216 <parameter name="Wait">
1217 <para>The caller's wait time.</para>
1218 </parameter>
1219 <parameter name="Priority">
1220 <para>The caller's priority within the queue.</para>
1221 </parameter>
1222 </syntax>
1223 <see-also>
1224 <ref type="managerEvent">QueueParams</ref>
1225 <ref type="managerEvent">QueueMember</ref>
1226 </see-also>
1227 </managerEventInstance>
1228 </managerEvent>
1229 <managerEvent language="en_US" name="QueueMemberStatus">
1230 <managerEventInstance class="EVENT_FLAG_AGENT">
1231 <since>
1232 <version>12.0.0</version>
1233 </since>
1234 <synopsis>Raised when a Queue member's status has changed.</synopsis>
1235 <syntax>
1236 <parameter name="Queue">
1237 <para>The name of the queue.</para>
1238 </parameter>
1239 <parameter name="MemberName">
1240 <para>The name of the queue member.</para>
1241 </parameter>
1242 <parameter name="Interface">
1243 <para>The queue member's channel technology or location.</para>
1244 </parameter>
1245 <parameter name="StateInterface">
1246 <para>Channel technology or location from which to read device state changes.</para>
1247 </parameter>
1248 <parameter name="Membership">
1249 <enumlist>
1250 <enum name="dynamic"/>
1251 <enum name="realtime"/>
1252 <enum name="static"/>
1253 </enumlist>
1254 </parameter>
1255 <parameter name="Penalty">
1256 <para>The penalty associated with the queue member.</para>
1257 </parameter>
1258 <parameter name="CallsTaken">
1259 <para>The number of calls this queue member has serviced.</para>
1260 </parameter>
1261 <parameter name="LastCall">
1262 <para>The time this member last took a call, expressed in seconds since 00:00, Jan 1, 1970 UTC.</para>
1263 </parameter>
1264 <parameter name="LastPause">
1265 <para>The time when started last paused the queue member.</para>
1266 </parameter>
1267 <parameter name="LoginTime">
1268 <para>The time this member logged in to the queue, expressed in seconds since 00:00, Jan 1, 1970 UTC.</para>
1269 </parameter>
1270 <parameter name="InCall">
1271 <para>Set to 1 if member is in call. Set to 0 after LastCall time is updated.</para>
1272 <enumlist>
1273 <enum name="0"/>
1274 <enum name="1"/>
1275 </enumlist>
1276 </parameter>
1277 <parameter name="Status">
1278 <para>The numeric device state status of the queue member.</para>
1279 <enumlist>
1280 <enum name="0"><para>AST_DEVICE_UNKNOWN</para></enum>
1281 <enum name="1"><para>AST_DEVICE_NOT_INUSE</para></enum>
1282 <enum name="2"><para>AST_DEVICE_INUSE</para></enum>
1283 <enum name="3"><para>AST_DEVICE_BUSY</para></enum>
1284 <enum name="4"><para>AST_DEVICE_INVALID</para></enum>
1285 <enum name="5"><para>AST_DEVICE_UNAVAILABLE</para></enum>
1286 <enum name="6"><para>AST_DEVICE_RINGING</para></enum>
1287 <enum name="7"><para>AST_DEVICE_RINGINUSE</para></enum>
1288 <enum name="8"><para>AST_DEVICE_ONHOLD</para></enum>
1289 </enumlist>
1290 </parameter>
1291 <parameter name="Paused">
1292 <enumlist>
1293 <enum name="0"/>
1294 <enum name="1"/>
1295 </enumlist>
1296 </parameter>
1297 <parameter name="PausedReason">
1298 <para>If set when paused, the reason the queue member was paused.</para>
1299 </parameter>
1300 <parameter name="Ringinuse">
1301 <enumlist>
1302 <enum name="0"/>
1303 <enum name="1"/>
1304 </enumlist>
1305 </parameter>
1306 <parameter name="Wrapuptime">
1307 <para>The Wrapup Time of the queue member. If this value is set will override the wrapup time of queue.</para>
1308 </parameter>
1309 </syntax>
1310 </managerEventInstance>
1311 </managerEvent>
1312 <managerEvent language="en_US" name="QueueMemberAdded">
1313 <managerEventInstance class="EVENT_FLAG_AGENT">
1314 <since>
1315 <version>12.0.0</version>
1316 </since>
1317 <synopsis>Raised when a member is added to the queue.</synopsis>
1318 <syntax>
1319 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter)" />
1320 </syntax>
1321 <see-also>
1322 <ref type="managerEvent">QueueMemberRemoved</ref>
1323 <ref type="application">AddQueueMember</ref>
1324 </see-also>
1325 </managerEventInstance>
1326 </managerEvent>
1327 <managerEvent language="en_US" name="QueueMemberRemoved">
1328 <managerEventInstance class="EVENT_FLAG_AGENT">
1329 <since>
1330 <version>12.0.0</version>
1331 </since>
1332 <synopsis>Raised when a member is removed from the queue.</synopsis>
1333 <syntax>
1334 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter)" />
1335 </syntax>
1336 <see-also>
1337 <ref type="managerEvent">QueueMemberAdded</ref>
1338 <ref type="application">RemoveQueueMember</ref>
1339 </see-also>
1340 </managerEventInstance>
1341 </managerEvent>
1342 <managerEvent language="en_US" name="QueueMemberPause">
1343 <managerEventInstance class="EVENT_FLAG_AGENT">
1344 <since>
1345 <version>12.2.0</version>
1346 </since>
1347 <synopsis>Raised when a member is paused/unpaused in the queue.</synopsis>
1348 <syntax>
1349 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter)" />
1350 </syntax>
1351 <see-also>
1352 <ref type="application">PauseQueueMember</ref>
1353 <ref type="application">UnpauseQueueMember</ref>
1354 </see-also>
1355 </managerEventInstance>
1356 </managerEvent>
1357 <managerEvent language="en_US" name="QueueMemberPenalty">
1358 <managerEventInstance class="EVENT_FLAG_AGENT">
1359 <since>
1360 <version>12.0.0</version>
1361 </since>
1362 <synopsis>Raised when a member's penalty is changed.</synopsis>
1363 <syntax>
1364 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter)" />
1365 </syntax>
1366 <see-also>
1367 <ref type="function">QUEUE_MEMBER</ref>
1368 </see-also>
1369 </managerEventInstance>
1370 </managerEvent>
1371 <managerEvent language="en_US" name="QueueMemberRinginuse">
1372 <managerEventInstance class="EVENT_FLAG_AGENT">
1373 <since>
1374 <version>12.0.0</version>
1375 </since>
1376 <synopsis>Raised when a member's ringinuse setting is changed.</synopsis>
1377 <syntax>
1378 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter)" />
1379 </syntax>
1380 <see-also>
1381 <ref type="function">QUEUE_MEMBER</ref>
1382 </see-also>
1383 </managerEventInstance>
1384 </managerEvent>
1385 <managerEvent language="en_US" name="QueueCallerJoin">
1386 <managerEventInstance class="EVENT_FLAG_AGENT">
1387 <since>
1388 <version>12.0.0</version>
1389 </since>
1390 <synopsis>Raised when a caller joins a Queue.</synopsis>
1391 <syntax>
1392 <channel_snapshot/>
1393 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1394 <parameter name="Position">
1395 <para>This channel's current position in the queue.</para>
1396 </parameter>
1397 <parameter name="Count">
1398 <para>The total number of channels in the queue.</para>
1399 </parameter>
1400 </syntax>
1401 <see-also>
1402 <ref type="managerEvent">QueueCallerLeave</ref>
1403 <ref type="application">Queue</ref>
1404 </see-also>
1405 </managerEventInstance>
1406 </managerEvent>
1407 <managerEvent language="en_US" name="QueueCallerLeave">
1408 <managerEventInstance class="EVENT_FLAG_AGENT">
1409 <since>
1410 <version>12.0.0</version>
1411 </since>
1412 <synopsis>Raised when a caller leaves a Queue.</synopsis>
1413 <syntax>
1414 <channel_snapshot/>
1415 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1416 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueCallerJoin']/managerEventInstance/syntax/parameter[@name='Count'])" />
1417 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueCallerJoin']/managerEventInstance/syntax/parameter[@name='Position'])" />
1418 </syntax>
1419 <see-also>
1420 <ref type="managerEvent">QueueCallerJoin</ref>
1421 </see-also>
1422 </managerEventInstance>
1423 </managerEvent>
1424 <managerEvent language="en_US" name="QueueCallerAbandon">
1425 <managerEventInstance class="EVENT_FLAG_AGENT">
1426 <since>
1427 <version>12.0.0</version>
1428 </since>
1429 <synopsis>Raised when a caller abandons the queue.</synopsis>
1430 <syntax>
1431 <channel_snapshot/>
1432 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1433 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueCallerJoin']/managerEventInstance/syntax/parameter[@name='Position'])" />
1434 <parameter name="OriginalPosition">
1435 <para>The channel's original position in the queue.</para>
1436 </parameter>
1437 <parameter name="HoldTime">
1438 <para>The time the channel was in the queue, expressed in seconds since 00:00, Jan 1, 1970 UTC.</para>
1439 </parameter>
1440 </syntax>
1441 </managerEventInstance>
1442 </managerEvent>
1443 <managerEvent language="en_US" name="AgentCalled">
1444 <managerEventInstance class="EVENT_FLAG_AGENT">
1445 <since>
1446 <version>12.0.0</version>
1447 </since>
1448 <synopsis>Raised when an queue member is notified of a caller in the queue.</synopsis>
1449 <syntax>
1450 <channel_snapshot/>
1451 <channel_snapshot prefix="Dest"/>
1452 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1453 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='MemberName'])" />
1454 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Interface'])" />
1455 </syntax>
1456 <see-also>
1457 <ref type="managerEvent">AgentRingNoAnswer</ref>
1458 <ref type="managerEvent">AgentComplete</ref>
1459 <ref type="managerEvent">AgentConnect</ref>
1460 </see-also>
1461 </managerEventInstance>
1462 </managerEvent>
1463 <managerEvent language="en_US" name="AgentRingNoAnswer">
1464 <managerEventInstance class="EVENT_FLAG_AGENT">
1465 <since>
1466 <version>12.0.0</version>
1467 </since>
1468 <synopsis>Raised when a queue member is notified of a caller in the queue and fails to answer.</synopsis>
1469 <syntax>
1470 <channel_snapshot/>
1471 <channel_snapshot prefix="Dest"/>
1472 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1473 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='MemberName'])" />
1474 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Interface'])" />
1475 <parameter name="RingTime">
1476 <para>The time the queue member was rung, expressed in seconds since 00:00, Jan 1, 1970 UTC.</para>
1477 </parameter>
1478 </syntax>
1479 <see-also>
1480 <ref type="managerEvent">AgentCalled</ref>
1481 </see-also>
1482 </managerEventInstance>
1483 </managerEvent>
1484 <managerEvent language="en_US" name="AgentComplete">
1485 <managerEventInstance class="EVENT_FLAG_AGENT">
1486 <since>
1487 <version>12.0.0</version>
1488 </since>
1489 <synopsis>Raised when a queue member has finished servicing a caller in the queue.</synopsis>
1490 <syntax>
1491 <channel_snapshot/>
1492 <channel_snapshot prefix="Dest"/>
1493 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1494 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='MemberName'])" />
1495 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Interface'])" />
1496 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueCallerAbandon']/managerEventInstance/syntax/parameter[@name='HoldTime'])" />
1497 <parameter name="TalkTime">
1498 <para>The time the queue member talked with the caller in the queue, expressed in seconds since 00:00, Jan 1, 1970 UTC.</para>
1499 </parameter>
1500 <parameter name="Reason">
1501 <enumlist>
1502 <enum name="caller"/>
1503 <enum name="agent"/>
1504 <enum name="transfer"/>
1505 </enumlist>
1506 </parameter>
1507 </syntax>
1508 <see-also>
1509 <ref type="managerEvent">AgentCalled</ref>
1510 <ref type="managerEvent">AgentConnect</ref>
1511 </see-also>
1512 </managerEventInstance>
1513 </managerEvent>
1514 <managerEvent language="en_US" name="AgentDump">
1515 <managerEventInstance class="EVENT_FLAG_AGENT">
1516 <since>
1517 <version>12.0.0</version>
1518 </since>
1519 <synopsis>Raised when a queue member hangs up on a caller in the queue.</synopsis>
1520 <syntax>
1521 <channel_snapshot/>
1522 <channel_snapshot prefix="Dest"/>
1523 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1524 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='MemberName'])" />
1525 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Interface'])" />
1526 </syntax>
1527 <see-also>
1528 <ref type="managerEvent">AgentCalled</ref>
1529 <ref type="managerEvent">AgentConnect</ref>
1530 </see-also>
1531 </managerEventInstance>
1532 </managerEvent>
1533 <managerEvent language="en_US" name="AgentConnect">
1534 <managerEventInstance class="EVENT_FLAG_AGENT">
1535 <since>
1536 <version>12.0.0</version>
1537 </since>
1538 <synopsis>Raised when a queue member answers and is bridged to a caller in the queue.</synopsis>
1539 <syntax>
1540 <channel_snapshot/>
1541 <channel_snapshot prefix="Dest"/>
1542 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Queue'])" />
1543 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='MemberName'])" />
1544 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueMemberStatus']/managerEventInstance/syntax/parameter[@name='Interface'])" />
1545 <xi:include xpointer="xpointer(/docs/managerEvent[@name='AgentRingNoAnswer']/managerEventInstance/syntax/parameter[@name='RingTime'])" />
1546 <xi:include xpointer="xpointer(/docs/managerEvent[@name='QueueCallerAbandon']/managerEventInstance/syntax/parameter[@name='HoldTime'])" />
1547 </syntax>
1548 <see-also>
1549 <ref type="managerEvent">AgentCalled</ref>
1550 <ref type="managerEvent">AgentComplete</ref>
1551 <ref type="managerEvent">AgentDump</ref>
1552 </see-also>
1553 </managerEventInstance>
1554 </managerEvent>
1555 ***/
1556
1557enum {
1559 OPT_GO_ON = (1 << 1),
1568 OPT_NO_RETRY = (1 << 10),
1569 OPT_RINGING = (1 << 11),
1580};
1581
1582enum {
1587 /* note: this entry _MUST_ be the last one in the enum */
1590
1615
1616
1618 AQMFLAG_PAUSED = (1 << 1),
1619 AQMFLAG_REASON = (1 << 2),
1620};
1621
1624 AQM_OPT_ARG_ARRAY_SIZE, /* Always last element of the enum */
1625};
1626
1631
1632enum {
1641};
1642
1643enum {
1648
1655
1656static const struct strategy {
1658 const char *name;
1659} strategies[] = {
1660 { QUEUE_STRATEGY_RINGALL, "ringall" },
1661 { QUEUE_STRATEGY_LEASTRECENT, "leastrecent" },
1662 { QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" },
1663 { QUEUE_STRATEGY_RANDOM, "random" },
1664 { QUEUE_STRATEGY_RRMEMORY, "rrmemory" },
1665 { QUEUE_STRATEGY_RRMEMORY, "roundrobin" },
1666 { QUEUE_STRATEGY_LINEAR, "linear" },
1667 { QUEUE_STRATEGY_WRANDOM, "wrandom"},
1668 { QUEUE_STRATEGY_RRORDERED, "rrordered"},
1670
1671static const struct autopause {
1673 const char *name;
1674} autopausesmodes [] = {
1675 { QUEUE_AUTOPAUSE_OFF,"no" },
1676 { QUEUE_AUTOPAUSE_ON, "yes" },
1677 { QUEUE_AUTOPAUSE_ALL,"all" },
1679
1680#define DEFAULT_RETRY 5
1681#define DEFAULT_TIMEOUT 15
1682#define RECHECK 1 /*!< Recheck every second to see we we're at the top yet */
1683#define MAX_PERIODIC_ANNOUNCEMENTS 10 /*!< The maximum periodic announcements we can have */
1684/*!
1685 * \brief The minimum number of seconds between position announcements.
1686 * \note The default value of 15 provides backwards compatibility.
1687 */
1688#define DEFAULT_MIN_ANNOUNCE_FREQUENCY 15
1689
1690#define MAX_QUEUE_BUCKETS 53
1691
1692#define RES_OKAY 0 /*!< Action completed */
1693#define RES_EXISTS (-1) /*!< Entry already exists */
1694#define RES_OUTOFMEMORY (-2) /*!< Out of memory */
1695#define RES_NOSUCHQUEUE (-3) /*!< No such queue */
1696#define RES_NOT_DYNAMIC (-4) /*!< Member is not dynamic */
1697#define RES_NOT_CALLER (-5) /*!< Caller not found */
1698
1699static char *app = "Queue";
1700
1701static char *app_aqm = "AddQueueMember" ;
1702
1703static char *app_rqm = "RemoveQueueMember" ;
1704
1705static char *app_pqm = "PauseQueueMember" ;
1706
1707static char *app_upqm = "UnpauseQueueMember" ;
1708
1709static char *app_ql = "QueueLog" ;
1710
1711static char *app_qupd = "QueueUpdate";
1712
1713/*! \brief Persistent Members astdb family */
1714static const char * const pm_family = "Queue/PersistentMembers";
1715
1716/*! \brief queues.conf [general] option */
1718
1719/*! \brief Records that one or more queues use weight */
1720static int use_weight;
1721
1722/*! \brief queues.conf [general] option */
1724
1725/*! \brief queues.conf [general] option */
1727
1728/*! \brief queues.conf [general] option */
1730
1731/*! \brief queuerules.conf [general] option */
1733
1734/*! \brief Subscription to device state change messages */
1736
1737/*! \brief queues.conf [general] option */
1739
1740/*! \brief queues.conf [general] option */
1742
1743/*! \brief queues.conf [general] option */
1745
1746/*! \brief queues.conf [general] option */
1748
1749/*! \brief queues.conf [general] option */
1751
1752/*! \brief name of the ringinuse field in the realtime database */
1754
1755/*! \brief does realtime backend support reason_paused */
1757
1769
1770static const struct {
1772 char *text;
1773} queue_results[] = {
1774 { QUEUE_UNKNOWN, "UNKNOWN" },
1775 { QUEUE_TIMEOUT, "TIMEOUT" },
1776 { QUEUE_JOINEMPTY,"JOINEMPTY" },
1777 { QUEUE_LEAVEEMPTY, "LEAVEEMPTY" },
1778 { QUEUE_JOINUNAVAIL, "JOINUNAVAIL" },
1779 { QUEUE_LEAVEUNAVAIL, "LEAVEUNAVAIL" },
1780 { QUEUE_FULL, "FULL" },
1781 { QUEUE_CONTINUE, "CONTINUE" },
1782 { QUEUE_WITHDRAW, "WITHDRAW" },
1784
1789
1790/*! \brief We define a custom "local user" structure because we
1791 * use it not only for keeping track of what is in use but
1792 * also for keeping track of who we're dialing.
1793 *
1794 * There are two "links" defined in this structure, q_next and call_next.
1795 * q_next links ALL defined callattempt structures into a linked list. call_next is
1796 * a link which allows for a subset of the callattempts to be traversed. This subset
1797 * is used in wait_for_answer so that irrelevant callattempts are not traversed. This
1798 * also is helpful so that queue logs are always accurate in the case where a call to
1799 * a member times out, especially if using the ringall strategy.
1800*/
1801
1806 char interface[256]; /*!< An Asterisk dial string (not a channel name) */
1809 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
1811 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
1813 /*! TRUE if the connected line update is blocked. */
1815 /*! TRUE if caller id is not available for connected line */
1816 unsigned int dial_callerid_absent:1;
1817 /*! TRUE if the call is still active */
1818 unsigned int stillgoing:1;
1820 /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
1822};
1823
1824
1826 struct call_queue *parent; /*!< What queue is our parent */
1827 char moh[MAX_MUSICCLASS]; /*!< Name of musiconhold to be used */
1828 char announce[PATH_MAX]; /*!< Announcement to play for member when call is answered */
1829 char context[AST_MAX_CONTEXT]; /*!< Context when user exits queue */
1830 char digits[AST_MAX_EXTENSION]; /*!< Digits entered while in queue */
1831 const char *predial_callee; /*!< Gosub app arguments for outgoing calls. NULL if not supplied. */
1832 int valid_digits; /*!< Digits entered correspond to valid extension. Exited */
1833 int pos; /*!< Where we are in the queue */
1834 int prio; /*!< Our priority */
1835 int last_pos_said; /*!< Last position we told the user */
1836 int ring_when_ringing; /*!< Should we only use ring indication when a channel is ringing? */
1837 time_t last_periodic_announce_time; /*!< The last time we played a periodic announcement */
1838 int last_periodic_announce_sound; /*!< The last periodic announcement we made */
1839 time_t last_pos; /*!< Last time we told the user their position */
1840 int opos; /*!< Where we started in the queue */
1841 int handled; /*!< Whether our call was handled */
1842 int pending; /*!< Non-zero if we are attempting to call a member */
1843 int max_penalty; /*!< Limit the members that can take this call to this penalty or lower */
1844 int min_penalty; /*!< Limit the members that can take this call to this penalty or higher */
1845 int raise_penalty; /*!< Float lower penalty members to a minimum penalty */
1846 int raise_respect_min; /*!< A switch raise_penalty should respect min_penalty not just max_penalty */
1847 int linpos; /*!< If using linear strategy, what position are we at? */
1848 int linwrapped; /*!< Is the linpos wrapped? */
1849 time_t start; /*!< When we started holding */
1850 time_t expire; /*!< When this entry should expire (time out of queue) */
1851 int cancel_answered_elsewhere; /*!< Whether we should force the CAE flag on this call (C) option*/
1852 unsigned int withdraw:1; /*!< Should this call exit the queue at its next iteration? Used for QueueWithdrawCaller */
1853 char *withdraw_info; /*!< Optional info passed by the caller of QueueWithdrawCaller */
1854 struct ast_channel *chan; /*!< Our channel */
1855 AST_LIST_HEAD_NOLOCK(,penalty_rule) qe_rules; /*!< Local copy of the queue's penalty rules */
1856 struct penalty_rule *pr; /*!< Pointer to the next penalty rule to implement */
1857 struct queue_ent *next; /*!< The next queue entry */
1858};
1859
1860struct member {
1861 char interface[AST_CHANNEL_NAME]; /*!< Technology/Location to dial to reach this member*/
1862 char state_exten[AST_MAX_EXTENSION]; /*!< Extension to get state from (if using hint) */
1863 char state_context[AST_MAX_CONTEXT]; /*!< Context to use when getting state (if using hint) */
1864 char state_interface[AST_CHANNEL_NAME]; /*!< Technology/Location from which to read devicestate changes */
1865 int state_id; /*!< Extension state callback id (if using hint) */
1866 char membername[80]; /*!< Member name to use in queue logs */
1867 int penalty; /*!< Are we a last resort? */
1868 int calls; /*!< Number of calls serviced by this member */
1869 int dynamic; /*!< Are we dynamically added? */
1870 int realtime; /*!< Is this member realtime? */
1871 int status; /*!< Status of queue member */
1872 int paused; /*!< Are we paused (not accepting calls)? */
1873 char reason_paused[80]; /*!< Reason of paused if member is paused */
1874 int queuepos; /*!< In what order (pertains to certain strategies) should this member be called? */
1875 int callcompletedinsl; /*!< Whether the current call was completed within service level */
1876 int wrapuptime; /*!< Wrapup Time */
1877 time_t starttime; /*!< The time at which the member answered the current caller. */
1878 time_t lastcall; /*!< When last successful call was hungup */
1879 time_t lastpause; /*!< When started the last pause */
1880 time_t logintime; /*!< The time when started the login */
1881 struct call_queue *lastqueue; /*!< Last queue we received a call */
1882 unsigned int dead:1; /*!< Used to detect members deleted in realtime */
1883 unsigned int delme:1; /*!< Flag to delete entry on reload */
1884 char rt_uniqueid[80]; /*!< Unique id of realtime member entry */
1885 unsigned int ringinuse:1; /*!< Flag to ring queue members even if their status is 'inuse' */
1886};
1887
1898
1903
1904/* values used in multi-bit flags in call_queue */
1905#define ANNOUNCEHOLDTIME_ALWAYS 1
1906#define ANNOUNCEHOLDTIME_ONCE 2
1907#define QUEUE_EVENT_VARIABLES 3
1908
1910 int time; /*!< Number of seconds that need to pass before applying this rule */
1911 int max_value; /*!< The amount specified in the penalty rule for max penalty */
1912 int min_value; /*!< The amount specified in the penalty rule for min penalty */
1913 int raise_value; /*!< The amount specified in the penalty rule for min penalty */
1914 int max_relative; /*!< Is the max adjustment relative? 1 for relative, 0 for absolute */
1915 int min_relative; /*!< Is the min adjustment relative? 1 for relative, 0 for absolute */
1916 int raise_relative; /*!< Is the min adjustment relative? 1 for relative, 0 for absolute */
1917 int raise_respect_min; /*!< A switch raise_penalty should respect min_penalty not just max_penalty */
1918 AST_LIST_ENTRY(penalty_rule) list; /*!< Next penalty_rule */
1919};
1920
1921#define ANNOUNCEPOSITION_YES 1 /*!< We announce position */
1922#define ANNOUNCEPOSITION_NO 2 /*!< We don't announce position */
1923#define ANNOUNCEPOSITION_MORE_THAN 3 /*!< We say "Currently there are more than <limit>" */
1924#define ANNOUNCEPOSITION_LIMIT 4 /*!< We not announce position more than <limit> */
1925
1928 /*! Queue name */
1930 /*! Music on Hold class */
1932 /*! Announcement to play when call is answered */
1934 /*! Exit context */
1936 /*! Gosub to run upon member connection */
1938 /*! Default rule to use if none specified in call to Queue() */
1940 /*! Sound file: "Your call is now first in line" (def. queue-youarenext) */
1942 /*! Sound file: "There are currently" (def. queue-thereare) */
1944 /*! Sound file: "calls waiting to speak to a representative." (def. queue-callswaiting) */
1946 /*! Sound file: "Currently there are more than" (def. queue-quantity1) */
1948 /*! Sound file: "callers waiting to speak with a representative" (def. queue-quantity2) */
1950 /*! Sound file: "The current estimated total holdtime is" (def. queue-holdtime) */
1952 /*! Sound file: "minutes." (def. queue-minutes) */
1954 /*! Sound file: "minute." (def. queue-minute) */
1956 /*! Sound file: "seconds." (def. queue-seconds) */
1958 /*! Sound file: "Thank you for your patience." (def. queue-thankyou) */
1960 /*! Sound file: Custom announce for caller, no default */
1962 /*! Sound file: "Hold time" (def. queue-reporthold) */
1965 /*! Sound files: Custom announce, no default */
1967 unsigned int dead:1;
1968 unsigned int ringinuse:1;
1969 unsigned int announce_to_first_user:1; /*!< Whether or not we announce to the first user in a queue */
1970 unsigned int setinterfacevar:1;
1971 unsigned int setqueuevar:1;
1972 unsigned int setqueueentryvar:1;
1973 unsigned int reportholdtime:1;
1974 unsigned int wrapped:1;
1975 unsigned int timeoutrestart:1;
1976 unsigned int announceholdtime:2;
1977 unsigned int announceposition:3;
1978 unsigned int announceposition_only_up:1; /*!< Only announce position if it has improved */
1980 unsigned int realtime:1;
1981 unsigned int found:1;
1983 unsigned int autopausebusy:1;
1984 unsigned int autopauseunavail:1;
1987 int announcepositionlimit; /*!< How many positions we announce? */
1988 int announcefrequency; /*!< How often to announce their position */
1989 int minannouncefrequency; /*!< The minimum number of seconds between position announcements (def. 15) */
1990 int periodicannouncestartdelay; /*!< How long into the queue should the periodic accouncement start */
1991 int periodicannouncefrequency; /*!< How often to play periodic announcement */
1992 int numperiodicannounce; /*!< The number of periodic announcements configured */
1993 int randomperiodicannounce; /*!< Are periodic announcements randomly chosen */
1994 int roundingseconds; /*!< How many seconds do we round to? */
1995 int holdtime; /*!< Current avg holdtime, based on an exponential average */
1996 int talktime; /*!< Current avg talktime, based on the same exponential average */
1997 int callscompleted; /*!< Number of queue calls completed */
1998 int callsabandoned; /*!< Number of queue calls abandoned */
1999 int callsabandonedinsl; /*!< Number of queue calls abandoned in servicelevel */
2000 int servicelevel; /*!< seconds setting for servicelevel*/
2001 int callscompletedinsl; /*!< Number of calls answered with servicelevel*/
2002 char monfmt[8]; /*!< Format to use when recording calls */
2003 int count; /*!< How many entries */
2004 int maxlen; /*!< Max number of entries */
2005 int wrapuptime; /*!< Wrapup Time */
2006 int penaltymemberslimit; /*!< Disregard penalty when queue has fewer than this many members */
2007
2008 int retry; /*!< Retry calling everyone after this amount of time */
2009 int timeout; /*!< How long to wait for an answer */
2010 int weight; /*!< Respective weight */
2011 int autopause; /*!< Auto pause queue members if they fail to answer */
2012 int autopausedelay; /*!< Delay auto pause for autopausedelay seconds since last call */
2013 int timeoutpriority; /*!< Do we allow a fraction of the timeout to occur for a ring? */
2014
2015 /* Queue strategy things */
2016 int rrpos; /*!< Round Robin - position */
2017 int memberdelay; /*!< Seconds to delay connecting member to caller */
2018 int autofill; /*!< Ignore the head call status and ring an available agent */
2019
2020 int log_restricted_caller_id:1; /*!< Whether log Restricted Caller ID */
2021
2022 struct ao2_container *members; /*!< Head of the list of members */
2023 struct queue_ent *head; /*!< Head of the list of callers */
2024 AST_LIST_ENTRY(call_queue) list; /*!< Next call queue */
2025 AST_LIST_HEAD_NOLOCK(, penalty_rule) rules; /*!< The list of penalty rules to invoke */
2026};
2027
2033
2035
2036static struct ao2_container *queues;
2037
2038static void update_realtime_members(struct call_queue *q);
2039static struct member *interface_exists(struct call_queue *q, const char *interface);
2040static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused);
2041static int update_queue(struct call_queue *q, struct member *member, int callcompletedinsl, time_t starttime);
2042
2043static struct member *find_member_by_queuename_and_interface(const char *queuename, const char *interface);
2044/*! \brief sets the QUEUESTATUS channel variable */
2045static void set_queue_result(struct ast_channel *chan, enum queue_result res)
2046{
2047 int i;
2048
2049 for (i = 0; i < ARRAY_LEN(queue_results); i++) {
2050 if (queue_results[i].id == res) {
2051 pbx_builtin_setvar_helper(chan, "QUEUESTATUS", queue_results[i].text);
2052 return;
2053 }
2054 }
2055}
2056
2057static const char *int2strat(int strategy)
2058{
2059 int x;
2060
2061 for (x = 0; x < ARRAY_LEN(strategies); x++) {
2062 if (strategy == strategies[x].strategy) {
2063 return strategies[x].name;
2064 }
2065 }
2066
2067 return "<unknown>";
2068}
2069
2070static int strat2int(const char *strategy)
2071{
2072 int x;
2073
2074 for (x = 0; x < ARRAY_LEN(strategies); x++) {
2075 if (!strcasecmp(strategy, strategies[x].name)) {
2076 return strategies[x].strategy;
2077 }
2078 }
2079
2080 return -1;
2081}
2082
2083static int autopause2int(const char *autopause)
2084{
2085 int x;
2086 /*This 'double check' that default value is OFF */
2088 return QUEUE_AUTOPAUSE_OFF;
2089 }
2090
2091 /*This 'double check' is to ensure old values works */
2092 if(ast_true(autopause)) {
2093 return QUEUE_AUTOPAUSE_ON;
2094 }
2095
2096 for (x = 0; x < ARRAY_LEN(autopausesmodes); x++) {
2097 if (!strcasecmp(autopause, autopausesmodes[x].name)) {
2098 return autopausesmodes[x].autopause;
2099 }
2100 }
2101
2102 /*This 'double check' that default value is OFF */
2103 return QUEUE_AUTOPAUSE_OFF;
2104}
2105
2106static int queue_hash_cb(const void *obj, const int flags)
2107{
2108 const struct call_queue *q = obj;
2109
2110 return ast_str_case_hash(q->name);
2111}
2112
2113static int queue_cmp_cb(void *obj, void *arg, int flags)
2114{
2115 struct call_queue *q = obj, *q2 = arg;
2116 return !strcasecmp(q->name, q2->name) ? CMP_MATCH | CMP_STOP : 0;
2117}
2118
2119/*!
2120 * \brief Return wrapuptime
2121 *
2122 * This function checks if wrapuptime in member is set and return this value.
2123 * Otherwise return value the wrapuptime in the queue configuration
2124 * \return integer value
2125 */
2126static int get_wrapuptime(struct call_queue *q, struct member *member)
2127{
2128 if (member->wrapuptime) {
2129 return member->wrapuptime;
2130 }
2131 return q->wrapuptime;
2132}
2133
2134/*! \internal
2135 * \brief ao2_callback, Decreases queuepos of all followers with a queuepos greater than arg.
2136 * \param obj the member being acted on
2137 * \param arg pointer to an integer containing the position value that was removed and requires reduction for anything above
2138 * \param flag unused
2139 */
2140static int queue_member_decrement_followers(void *obj, void *arg, int flag)
2141{
2142 struct member *mem = obj;
2143 int *decrement_followers_after = arg;
2144
2145 if (mem->queuepos > *decrement_followers_after) {
2146 mem->queuepos--;
2147 }
2148
2149 return 0;
2150}
2151
2152/*! \internal
2153 * \brief ao2_callback, finds members in a queue marked for deletion and in a cascading fashion runs queue_member_decrement_followers
2154 * on them. This callback should always be ran before performing mass unlinking of delmarked members from queues.
2155 * \param obj member being acted on
2156 * \param arg pointer to the queue members are being removed from
2157 * \param flag unused
2158 */
2159static int queue_delme_members_decrement_followers(void *obj, void *arg, int flag)
2160{
2161 struct member *mem = obj;
2162 struct call_queue *queue = arg;
2163 int rrpos = mem->queuepos;
2164
2165 if (mem->delme) {
2167 }
2168
2169 return 0;
2170}
2171
2172/*! \internal
2173 * \brief Use this to decrement followers during removal of a member
2174 * \param queue which queue the member is being removed from
2175 * \param mem which member is being removed from the queue
2176 */
2177static void queue_member_follower_removal(struct call_queue *queue, struct member *mem)
2178{
2179 int pos = mem->queuepos;
2180
2181 /* If the position being removed is less than the current place in the queue, reduce the queue position by one so that we don't skip the member
2182 * who would have been next otherwise. */
2183 if (pos < queue->rrpos) {
2184 queue->rrpos--;
2185 }
2186
2188}
2189
2190#define queue_ref(q) ao2_bump(q)
2191#define queue_unref(q) ({ ao2_cleanup(q); NULL; })
2192#define queue_t_ref(q, tag) ao2_t_bump(q, tag)
2193#define queue_t_unref(q, tag) ({ ao2_t_cleanup(q, tag); NULL; })
2194#define queues_t_link(c, q, tag) ao2_t_link(c, q, tag)
2195#define queues_t_unlink(c, q, tag) ao2_t_unlink(c, q, tag)
2196
2197/*! \brief Set variables of queue */
2198static void set_queue_variables(struct call_queue *q, struct ast_channel *chan)
2199{
2200 char interfacevar[256]="";
2201 float sl = 0;
2202
2203 ao2_lock(q);
2204
2205 if (q->setqueuevar) {
2206 sl = 0;
2207 if (q->callscompleted > 0) {
2208 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
2209 }
2210
2211 snprintf(interfacevar, sizeof(interfacevar),
2212 "QUEUENAME=%s,QUEUEMAX=%d,QUEUESTRATEGY=%s,QUEUECALLS=%d,QUEUEHOLDTIME=%d,QUEUETALKTIME=%d,QUEUECOMPLETED=%d,QUEUEABANDONED=%d,QUEUESRVLEVEL=%d,QUEUESRVLEVELPERF=%2.1f",
2214
2215 ao2_unlock(q);
2216
2217 pbx_builtin_setvar_multiple(chan, interfacevar);
2218 } else {
2219 ao2_unlock(q);
2220 }
2221}
2222
2223/*! \brief Insert the 'new' entry after the 'prev' entry of queue 'q' */
2224static inline void insert_entry(struct call_queue *q, struct queue_ent *prev, struct queue_ent *new, int *pos)
2225{
2226 struct queue_ent *cur;
2227
2228 if (!q || !new)
2229 return;
2230 if (prev) {
2231 cur = prev->next;
2232 prev->next = new;
2233 } else {
2234 cur = q->head;
2235 q->head = new;
2236 }
2237 new->next = cur;
2238
2239 /* every queue_ent must have a reference to it's parent call_queue, this
2240 * reference does not go away until the end of the queue_ent's life, meaning
2241 * that even when the queue_ent leaves the call_queue this ref must remain. */
2242 if (!new->parent) {
2243 queue_ref(q);
2244 new->parent = q;
2245 }
2246 new->pos = ++(*pos);
2247 new->opos = *pos;
2248}
2249
2251{
2253 RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
2254 RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
2255
2256 channel_string = ast_manager_build_channel_state_string(obj->snapshot);
2257 event_string = ast_manager_str_from_json_object(obj->blob, NULL);
2258 if (!channel_string || !event_string) {
2259 return NULL;
2260 }
2261
2263 "%s"
2264 "%s",
2265 ast_str_buffer(channel_string),
2266 ast_str_buffer(event_string));
2267}
2268
2270{
2271 return queue_channel_to_ami("QueueCallerJoin", message);
2272}
2273
2275{
2276 return queue_channel_to_ami("QueueCallerLeave", message);
2277}
2278
2280{
2281 return queue_channel_to_ami("QueueCallerAbandon", message);
2282}
2283
2284STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_join_type,
2286 );
2287STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_leave_type,
2289 );
2290STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_abandon_type,
2292 );
2293
2295{
2296 struct ast_json_payload *payload = stasis_message_data(message);
2297 RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
2298
2299 event_string = ast_manager_str_from_json_object(payload->json, NULL);
2300 if (!event_string) {
2301 return NULL;
2302 }
2303
2305 "%s",
2306 ast_str_buffer(event_string));
2307}
2308
2310{
2311 return queue_member_to_ami("QueueMemberStatus", message);
2312}
2313
2315{
2316 return queue_member_to_ami("QueueMemberAdded", message);
2317}
2318
2320{
2321 return queue_member_to_ami("QueueMemberRemoved", message);
2322}
2323
2325{
2326 return queue_member_to_ami("QueueMemberPause", message);
2327}
2328
2330{
2331 return queue_member_to_ami("QueueMemberPenalty", message);
2332}
2333
2335{
2336 return queue_member_to_ami("QueueMemberRinginuse", message);
2337}
2338
2339STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_status_type,
2341 );
2342STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_added_type,
2344 );
2345STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_removed_type,
2347 );
2348STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_pause_type,
2350 );
2351STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_penalty_type,
2353 );
2354STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_ringinuse_type,
2356 );
2357
2359{
2362 struct ast_channel_snapshot *agent;
2363 RAII_VAR(struct ast_str *, caller_event_string, NULL, ast_free);
2364 RAII_VAR(struct ast_str *, agent_event_string, NULL, ast_free);
2365 RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
2366
2368 if (caller) {
2369 caller_event_string = ast_manager_build_channel_state_string(caller);
2370 if (!caller_event_string) {
2371 ast_log(LOG_NOTICE, "No caller event string, bailing\n");
2372 return NULL;
2373 }
2374 }
2375
2376 agent = ast_multi_channel_blob_get_channel(obj, "agent");
2377 if (agent) {
2378 agent_event_string = ast_manager_build_channel_state_string_prefix(agent, "Dest");
2379 if (!agent_event_string) {
2380 ast_log(LOG_NOTICE, "No agent event string, bailing\n");
2381 return NULL;
2382 }
2383 }
2384
2386 if (!event_string) {
2387 return NULL;
2388 }
2389
2391 "%s"
2392 "%s"
2393 "%s",
2394 caller_event_string ? ast_str_buffer(caller_event_string) : "",
2395 agent_event_string ? ast_str_buffer(agent_event_string) : "",
2396 ast_str_buffer(event_string));
2397}
2398
2400{
2401 return queue_multi_channel_to_ami("AgentCalled", message);
2402}
2403
2405{
2406 return queue_multi_channel_to_ami("AgentConnect", message);
2407}
2408
2410{
2411 return queue_multi_channel_to_ami("AgentComplete", message);
2412}
2413
2418
2420{
2421 return queue_multi_channel_to_ami("AgentRingNoAnswer", message);
2422}
2423
2424STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_called_type,
2426 );
2427STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_connect_type,
2429 );
2430STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_complete_type,
2432 );
2435 );
2436STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_ringnoanswer_type,
2438 );
2439
2441 struct ast_channel_snapshot *caller_snapshot,
2442 struct ast_channel_snapshot *agent_snapshot,
2443 struct stasis_message_type *type, struct ast_json *blob)
2444{
2445 RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
2446 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
2447
2448 if (!type) {
2449 return;
2450 }
2451
2452 payload = ast_multi_channel_blob_create(blob);
2453 if (!payload) {
2454 return;
2455 }
2456
2457 if (caller_snapshot) {
2458 ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
2459 } else {
2460 ast_debug(1, "Empty caller_snapshot; sending incomplete event\n");
2461 }
2462
2463 if (agent_snapshot) {
2464 ast_multi_channel_blob_add_channel(payload, "agent", agent_snapshot);
2465 }
2466
2467 msg = stasis_message_create(type, payload);
2468 if (!msg) {
2469 return;
2470 }
2471
2472 stasis_publish(topic, msg);
2473}
2474
2475static void queue_publish_multi_channel_blob(struct ast_channel *caller, struct ast_channel *agent,
2476 struct stasis_message_type *type, struct ast_json *blob)
2477{
2478 RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
2479 RAII_VAR(struct ast_channel_snapshot *, agent_snapshot, NULL, ao2_cleanup);
2480
2481 ast_channel_lock(caller);
2482 caller_snapshot = ast_channel_snapshot_create(caller);
2483 ast_channel_unlock(caller);
2484 ast_channel_lock(agent);
2485 agent_snapshot = ast_channel_snapshot_create(agent);
2486 ast_channel_unlock(agent);
2487
2488 if (!caller_snapshot || !agent_snapshot) {
2489 return;
2490 }
2491
2493 agent_snapshot, type, blob);
2494}
2495
2496/*!
2497 * \internal
2498 * \brief Publish the member blob.
2499 * \since 12.0.0
2500 *
2501 * \param type Stasis message type to publish.
2502 * \param blob The information being published.
2503 *
2504 * \note The json blob reference is passed to this function.
2505 */
2507{
2508 RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
2509 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
2510
2511 if (!blob || !type) {
2512 ast_json_unref(blob);
2513 return;
2514 }
2515
2516 payload = ast_json_payload_create(blob);
2517 ast_json_unref(blob);
2518 if (!payload) {
2519 return;
2520 }
2521
2522 msg = stasis_message_create(type, payload);
2523 if (!msg) {
2524 return;
2525 }
2526
2528}
2529
2530static struct ast_json *queue_member_blob_create(struct call_queue *q, struct member *mem)
2531{
2532 return ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: i, s: i, s: i, s: i, s: i, s: i, s: i, s: i, s: s, s: i, s: i}",
2533 "Queue", q->name,
2534 "MemberName", mem->membername,
2535 "Interface", mem->interface,
2536 "StateInterface", mem->state_interface,
2537 "Membership", (mem->dynamic ? "dynamic" : (mem->realtime ? "realtime" : "static")),
2538 "Penalty", mem->penalty,
2539 "CallsTaken", mem->calls,
2540 "LastCall", (int)mem->lastcall,
2541 "LastPause", (int)mem->lastpause,
2542 "LoginTime", (int)mem->logintime,
2543 "InCall", mem->starttime ? 1 : 0,
2544 "Status", mem->status,
2545 "Paused", mem->paused,
2546 "PausedReason", mem->reason_paused,
2547 "Ringinuse", mem->ringinuse,
2548 "Wrapuptime", mem->wrapuptime);
2549}
2550
2551/*! \brief Check if members are available
2552 *
2553 * This function checks to see if members are available to be called. If any member
2554 * is available, the function immediately returns 0. If no members are available,
2555 * then -1 is returned.
2556 */
2557static int get_member_status(struct call_queue *q, int max_penalty, int min_penalty, int raise_penalty, enum empty_conditions conditions, int devstate, int raise_respect_min)
2558{
2559 struct member *member;
2560 struct ao2_iterator mem_iter;
2561
2562 ao2_lock(q);
2563 mem_iter = ao2_iterator_init(q->members, 0);
2564 for (; (member = ao2_iterator_next(&mem_iter)); ao2_ref(member, -1)) {
2565 int penalty = member->penalty;
2566 if (raise_penalty != INT_MAX && penalty < raise_penalty) {
2567 /* Check if we should respect minimum penalty threshold */
2568 if (raise_respect_min && penalty < min_penalty) {
2569 ast_debug(4, "%s penalty %d not raised (below min %d)\n", member->membername, penalty, min_penalty);
2570 } else {
2571 ast_debug(4, "%s is having his penalty raised up from %d to %d\n", member->membername, penalty, raise_penalty);
2572 penalty = raise_penalty;
2573 }
2574 }
2575 if ((max_penalty != INT_MAX && penalty > max_penalty) || (min_penalty != INT_MAX && penalty < min_penalty)) {
2576 if (conditions & QUEUE_EMPTY_PENALTY) {
2577 ast_debug(4, "%s is unavailable because his penalty is not between %d and %d\n", member->membername, min_penalty, max_penalty);
2578 continue;
2579 }
2580 }
2581
2582 switch (devstate ? ast_device_state(member->state_interface) : member->status) {
2583 case AST_DEVICE_INVALID:
2584 if (conditions & QUEUE_EMPTY_INVALID) {
2585 ast_debug(4, "%s is unavailable because his device state is 'invalid'\n", member->membername);
2586 break;
2587 }
2588 goto default_case;
2590 if (conditions & QUEUE_EMPTY_UNAVAILABLE) {
2591 ast_debug(4, "%s is unavailable because his device state is 'unavailable'\n", member->membername);
2592 break;
2593 }
2594 goto default_case;
2595 case AST_DEVICE_INUSE:
2596 if (conditions & QUEUE_EMPTY_INUSE) {
2597 ast_debug(4, "%s is unavailable because his device state is 'inuse'\n", member->membername);
2598 break;
2599 }
2600 goto default_case;
2601 case AST_DEVICE_RINGING:
2602 if (conditions & QUEUE_EMPTY_RINGING) {
2603 ast_debug(4, "%s is unavailable because his device state is 'ringing'\n", member->membername);
2604 break;
2605 }
2606 goto default_case;
2607 case AST_DEVICE_UNKNOWN:
2608 if (conditions & QUEUE_EMPTY_UNKNOWN) {
2609 ast_debug(4, "%s is unavailable because his device state is 'unknown'\n", member->membername);
2610 break;
2611 }
2612 /* Fall-through */
2613 default:
2614 default_case:
2615 if (member->paused && (conditions & QUEUE_EMPTY_PAUSED)) {
2616 ast_debug(4, "%s is unavailable because he is paused'\n", member->membername);
2617 break;
2618 } else if ((conditions & QUEUE_EMPTY_WRAPUP)
2619 && member->lastcall
2620 && get_wrapuptime(q, member)
2621 && (time(NULL) - get_wrapuptime(q, member) < member->lastcall)) {
2622 ast_debug(4, "%s is unavailable because it has only been %d seconds since his last call (wrapup time is %d)\n",
2623 member->membername, (int) (time(NULL) - member->lastcall), get_wrapuptime(q, member));
2624 break;
2625 } else {
2626 ao2_ref(member, -1);
2627 ao2_iterator_destroy(&mem_iter);
2628 ao2_unlock(q);
2629 ast_debug(4, "%s is available.\n", member->membername);
2630 return 0;
2631 }
2632 break;
2633 }
2634 }
2635 ao2_iterator_destroy(&mem_iter);
2636 ao2_unlock(q);
2637
2638 if (!devstate && (conditions & QUEUE_EMPTY_RINGING)) {
2639 /* member state still may be RINGING due to lag in event message - check again with device state */
2640 return get_member_status(q, max_penalty, min_penalty, raise_penalty, conditions, 1, raise_respect_min);
2641 }
2642 return -1;
2643}
2644
2645/*
2646 * A "pool" of member objects that calls are currently pending on. If an
2647 * agent is a member of multiple queues it's possible for that agent to be
2648 * called by each of the queues at the same time. This happens because device
2649 * state is slow to notify the queue app of one of it's member's being rung.
2650 * This "pool" allows us to track which members are currently being rung while
2651 * we wait on the device state change.
2652 */
2654#define MAX_CALL_ATTEMPT_BUCKETS 353
2655
2656static int pending_members_hash(const void *obj, const int flags)
2657{
2658 const struct member *object;
2659 const char *key;
2660
2661 switch (flags & OBJ_SEARCH_MASK) {
2662 case OBJ_SEARCH_KEY:
2663 key = obj;
2664 break;
2665 case OBJ_SEARCH_OBJECT:
2666 object = obj;
2667 key = object->interface;
2668 break;
2669 default:
2670 ast_assert(0);
2671 return 0;
2672 }
2673 return ast_str_case_hash(key);
2674}
2675
2676static int pending_members_cmp(void *obj, void *arg, int flags)
2677{
2678 const struct member *object_left = obj;
2679 const struct member *object_right = arg;
2680 const char *right_key = arg;
2681 int cmp;
2682
2683 switch (flags & OBJ_SEARCH_MASK) {
2684 case OBJ_SEARCH_OBJECT:
2685 right_key = object_right->interface;
2686 /* Fall through */
2687 case OBJ_SEARCH_KEY:
2688 cmp = strcasecmp(object_left->interface, right_key);
2689 break;
2691 /* Not supported by container. */
2692 ast_assert(0);
2693 return 0;
2694 default:
2695 cmp = 0;
2696 break;
2697 }
2698 if (cmp) {
2699 return 0;
2700 }
2701 return CMP_MATCH;
2702}
2703
2704static void pending_members_remove(struct member *mem)
2705{
2706 ast_debug(3, "Removed %s from pending_members\n", mem->membername);
2708}
2709
2710/*! \brief set a member's status based on device state of that member's state_interface.
2711 *
2712 * Lock interface list find sc, iterate through each queues queue_member list for member to
2713 * update state inside queues
2714*/
2715static void update_status(struct call_queue *q, struct member *m, const int status)
2716{
2717 if (m->status != status) {
2718 /* If this member has transitioned to being available then update their queue
2719 * information. If they are currently in a call then the leg to the agent will be
2720 * considered done and the call finished.
2721 */
2724 }
2725
2726 m->status = status;
2727
2728 /* Remove the member from the pending members pool only when the status changes.
2729 * This is not done unconditionally because we can occasionally see multiple
2730 * device state notifications of not in use after a previous call has ended,
2731 * including after we have initiated a new call. This is more likely to
2732 * happen when there is latency in the connection to the member.
2733 */
2735
2736 queue_publish_member_blob(queue_member_status_type(), queue_member_blob_create(q, m));
2737 }
2738}
2739
2740/*!
2741 * \internal
2742 * \brief Determine if a queue member is available
2743 * \retval 1 if the member is available
2744 * \retval 0 if the member is not available
2745 */
2746static int is_member_available(struct call_queue *q, struct member *mem)
2747{
2748 int available = 0;
2749 int wrapuptime;
2750
2751 switch (mem->status) {
2752 case AST_DEVICE_INVALID:
2754 break;
2755 case AST_DEVICE_INUSE:
2756 case AST_DEVICE_BUSY:
2757 case AST_DEVICE_RINGING:
2759 case AST_DEVICE_ONHOLD:
2760 if (!mem->ringinuse) {
2761 break;
2762 }
2763 /* else fall through */
2765 case AST_DEVICE_UNKNOWN:
2766 if (!mem->paused) {
2767 available = 1;
2768 }
2769 break;
2770 }
2771
2772 /* Let wrapuptimes override device state availability */
2773 wrapuptime = get_wrapuptime(q, mem);
2774 if (mem->lastcall && wrapuptime && (time(NULL) - wrapuptime < mem->lastcall)) {
2775 available = 0;
2776 }
2777 return available;
2778}
2779
2780/*! \brief set a member's status based on device state of that member's interface*/
2781static void device_state_cb(void *unused, struct stasis_subscription *sub, struct stasis_message *msg)
2782{
2783 struct ao2_iterator miter, qiter;
2784 struct ast_device_state_message *dev_state;
2785 struct member *m;
2786 struct call_queue *q;
2787 char interface[80], *slash_pos;
2788 int found = 0; /* Found this member in any queue */
2789 int found_member; /* Found this member in this queue */
2790 int avail = 0; /* Found an available member in this queue */
2791
2793 return;
2794 }
2795
2796 dev_state = stasis_message_data(msg);
2797 if (dev_state->eid) {
2798 /* ignore non-aggregate states */
2799 return;
2800 }
2801
2802 qiter = ao2_iterator_init(queues, 0);
2803 while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) {
2804 ao2_lock(q);
2805
2806 avail = 0;
2807 found_member = 0;
2808 miter = ao2_iterator_init(q->members, 0);
2809 for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) {
2810 if (!found_member) {
2811 ast_copy_string(interface, m->state_interface, sizeof(interface));
2812
2813 if ((slash_pos = strchr(interface, '/'))) {
2814 if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) {
2815 *slash_pos = '\0';
2816 }
2817 }
2818
2819 if (!strcasecmp(interface, dev_state->device)) {
2820 found_member = 1;
2821 update_status(q, m, dev_state->state);
2822 }
2823 }
2824
2825 /* check every member until we find one NOT_INUSE */
2826 if (!avail) {
2827 avail = is_member_available(q, m);
2828 }
2829 if (avail && found_member) {
2830 /* early exit as we've found an available member and the member of interest */
2831 ao2_ref(m, -1);
2832 break;
2833 }
2834 }
2835
2836 if (found_member) {
2837 found = 1;
2838 if (avail) {
2840 } else {
2842 }
2843 }
2844
2845 ao2_iterator_destroy(&miter);
2846
2847 ao2_unlock(q);
2848 queue_t_unref(q, "Done with iterator");
2849 }
2850 ao2_iterator_destroy(&qiter);
2851
2852 if (found) {
2853 ast_debug(1, "Device '%s' changed to state '%u' (%s)\n",
2854 dev_state->device,
2855 dev_state->state,
2856 ast_devstate2str(dev_state->state));
2857 } else {
2858 ast_debug(3, "Device '%s' changed to state '%u' (%s) but we don't care because they're not a member of any queue.\n",
2859 dev_state->device,
2860 dev_state->state,
2861 ast_devstate2str(dev_state->state));
2862 }
2863
2864 return;
2865}
2866
2867/*! \brief Helper function which converts from extension state to device state values */
2869{
2870 switch (state) {
2873 break;
2876 break;
2877 case AST_EXTENSION_BUSY:
2879 break;
2882 break;
2885 break;
2888 break;
2891 break;
2894 break;
2897 default:
2899 break;
2900 }
2901
2902 return state;
2903}
2904
2905/*!
2906 * \brief Returns if one context includes another context
2907 *
2908 * \param parent Parent context to search for child
2909 * \param child Context to check for inclusion in parent
2910 *
2911 * This function recursively checks if the context child is included in the context parent.
2912 *
2913 * \retval 1 if child is included in parent
2914 * \retval 0 if not
2915 */
2916static int context_included(const char *parent, const char *child);
2917static int context_included(const char *parent, const char *child)
2918{
2919 struct ast_context *c = NULL;
2920
2921 c = ast_context_find(parent);
2922 if (!c) {
2923 /* well, if parent doesn't exist, how can the child be included in it? */
2924 return 0;
2925 }
2926 if (!strcmp(ast_get_context_name(c), parent)) {
2927 /* found the context of the hint app_queue is using. Now, see
2928 if that context includes the one that just changed state */
2929 struct ast_include *inc = NULL;
2930
2931 while ((inc = (struct ast_include*) ast_walk_context_includes(c, inc))) {
2932 const char *includename = ast_get_include_name(inc);
2933 if (!strcasecmp(child, includename)) {
2934 return 1;
2935 }
2936 /* recurse on this context, for nested includes. The
2937 PBX extension parser will prevent infinite recursion. */
2938 if (context_included(includename, child)) {
2939 return 1;
2940 }
2941 }
2942 }
2943 return 0;
2944}
2945
2946static int extension_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
2947{
2948 struct ao2_iterator miter, qiter;
2949 struct member *m;
2950 struct call_queue *q;
2951 int state = info->exten_state;
2952 int found = 0, device_state = extensionstate2devicestate(state);
2953
2954 /* only interested in extension state updates involving device states */
2955 if (info->reason != AST_HINT_UPDATE_DEVICE) {
2956 return 0;
2957 }
2958
2959 qiter = ao2_iterator_init(queues, 0);
2960 while ((q = ao2_t_iterator_next(&qiter, "Iterate through queues"))) {
2961 ao2_lock(q);
2962
2963 miter = ao2_iterator_init(q->members, 0);
2964 for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) {
2965 if (!strcmp(m->state_exten, exten) &&
2967 /* context could be included in m->state_context. We need to check. */
2968 found = 1;
2969 update_status(q, m, device_state);
2970 }
2971 }
2972 ao2_iterator_destroy(&miter);
2973
2974 ao2_unlock(q);
2975 queue_t_unref(q, "Done with iterator");
2976 }
2977 ao2_iterator_destroy(&qiter);
2978
2979 if (found) {
2980 ast_debug(1, "Extension '%s@%s' changed to state '%d' (%s)\n", exten, context, device_state, ast_devstate2str(device_state));
2981 } else {
2982 ast_debug(3, "Extension '%s@%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n",
2983 exten, context, device_state, ast_devstate2str(device_state));
2984 }
2985
2986 return 0;
2987}
2988
2989/*! \brief Return the current state of a member */
2994
2995static void destroy_queue_member_cb(void *obj)
2996{
2997 struct member *mem = obj;
2998
2999 if (mem->state_id != -1) {
3001 }
3002}
3003
3004/*! \brief allocate space for new queue member and set fields based on parameters passed */
3005static struct member *create_queue_member(const char *interface, const char *membername, int penalty, int paused, const char *state_interface, int ringinuse, int wrapuptime)
3006{
3007 struct member *cur;
3008
3009 if ((cur = ao2_alloc(sizeof(*cur), destroy_queue_member_cb))) {
3010 cur->ringinuse = ringinuse;
3011 cur->penalty = penalty;
3012 cur->paused = paused;
3013 cur->wrapuptime = wrapuptime;
3014 if (paused) {
3015 time(&cur->lastpause); /* Update time of last pause */
3016 }
3017 time(&cur->logintime);
3018 ast_copy_string(cur->interface, interface, sizeof(cur->interface));
3021 } else {
3023 }
3025 ast_copy_string(cur->membername, membername, sizeof(cur->membername));
3026 } else {
3027 ast_copy_string(cur->membername, interface, sizeof(cur->membername));
3028 }
3029 if (!strchr(cur->interface, '/')) {
3030 ast_log(LOG_WARNING, "No location at interface '%s'\n", interface);
3031 }
3032 if (!strncmp(cur->state_interface, "hint:", 5)) {
3033 char *tmp = ast_strdupa(cur->state_interface), *context = tmp;
3034 char *exten = strsep(&context, "@") + 5;
3035
3036 ast_copy_string(cur->state_exten, exten, sizeof(cur->state_exten));
3037 ast_copy_string(cur->state_context, S_OR(context, "default"), sizeof(cur->state_context));
3038
3040 } else {
3041 cur->state_id = -1;
3042 }
3043 cur->status = get_queue_member_status(cur);
3044 }
3045
3046 return cur;
3047}
3048
3049
3050static int compress_char(const char c)
3051{
3052 if (c < 32) {
3053 return 0;
3054 } else if (c > 96) {
3055 return c - 64;
3056 }
3057 return c - 32;
3058}
3059
3060static int member_hash_fn(const void *obj, const int flags)
3061{
3062 const struct member *mem = obj;
3063 const char *interface = (flags & OBJ_KEY) ? obj : mem->interface;
3064 const char *chname = strchr(interface, '/');
3065 int ret = 0, i;
3066
3067 if (!chname) {
3068 chname = interface;
3069 }
3070 for (i = 0; i < 5 && chname[i]; i++) {
3071 ret += compress_char(chname[i]) << (i * 6);
3072 }
3073 return ret;
3074}
3075
3076static int member_cmp_fn(void *obj1, void *obj2, int flags)
3077{
3078 struct member *mem1 = obj1;
3079 struct member *mem2 = obj2;
3080 const char *interface = (flags & OBJ_KEY) ? obj2 : mem2->interface;
3081
3082 return strcasecmp(mem1->interface, interface) ? 0 : CMP_MATCH | CMP_STOP;
3083}
3084
3085/*!
3086 * \brief Initialize Queue default values.
3087 * \note the queue's lock must be held before executing this function
3088*/
3089static void init_queue(struct call_queue *q)
3090{
3091 int i;
3092 struct penalty_rule *pr_iter;
3093
3094 q->dead = 0;
3095 q->retry = DEFAULT_RETRY;
3097 q->maxlen = 0;
3098
3099 ast_string_field_set(q, announce, "");
3100 ast_string_field_set(q, context, "");
3101 ast_string_field_set(q, membergosub, "");
3102 ast_string_field_set(q, defaultrule, "");
3103
3104 q->announcefrequency = 0;
3106 q->announceholdtime = 1;
3108 q->announcepositionlimit = 10; /* Default 10 positions */
3109 q->announceposition = ANNOUNCEPOSITION_YES; /* Default yes */
3110 q->roundingseconds = 0; /* Default - don't announce seconds */
3111 q->servicelevel = 0;
3112 q->ringinuse = 1;
3114 q->setinterfacevar = 0;
3115 q->setqueuevar = 0;
3116 q->setqueueentryvar = 0;
3118 q->monfmt[0] = '\0';
3119 q->reportholdtime = 0;
3120 q->wrapuptime = 0;
3121 q->penaltymemberslimit = 0;
3122 q->joinempty = 0;
3123 q->leavewhenempty = 0;
3124 q->memberdelay = 0;
3125 q->weight = 0;
3126 q->timeoutrestart = 0;
3130 q->numperiodicannounce = 0;
3133 q->autopausebusy = 0;
3134 q->autopauseunavail = 0;
3136 q->autopausedelay = 0;
3138 if (!q->members) {
3140 /* linear strategy depends on order, so we have to place all members in a list */
3142 } else {
3145 }
3146 }
3147 q->found = 1;
3148
3149 ast_string_field_set(q, moh, "");
3150 ast_string_field_set(q, sound_next, "queue-youarenext");
3151 ast_string_field_set(q, sound_thereare, "queue-thereare");
3152 ast_string_field_set(q, sound_calls, "queue-callswaiting");
3153 ast_string_field_set(q, queue_quantity1, "queue-quantity1");
3154 ast_string_field_set(q, queue_quantity2, "queue-quantity2");
3155 ast_string_field_set(q, sound_holdtime, "queue-holdtime");
3156 ast_string_field_set(q, sound_minutes, "queue-minutes");
3157 ast_string_field_set(q, sound_minute, "queue-minute");
3158 ast_string_field_set(q, sound_seconds, "queue-seconds");
3159 ast_string_field_set(q, sound_thanks, "queue-thankyou");
3160 ast_string_field_set(q, sound_callerannounce, "");
3161 ast_string_field_set(q, sound_reporthold, "queue-reporthold");
3162
3163 if (!q->sound_periodicannounce[0]) {
3165 }
3166
3167 if (q->sound_periodicannounce[0]) {
3168 ast_str_set(&q->sound_periodicannounce[0], 0, "queue-periodic-announce");
3169 }
3170
3171 for (i = 1; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
3172 if (q->sound_periodicannounce[i]) {
3173 ast_str_set(&q->sound_periodicannounce[i], 0, "%s", "");
3174 }
3175 }
3176
3177 while ((pr_iter = AST_LIST_REMOVE_HEAD(&q->rules,list))) {
3178 ast_free(pr_iter);
3179 }
3180
3181 /* On restart assume no members are available.
3182 * The queue_avail hint is a boolean state to indicate whether a member is available or not.
3183 *
3184 * This seems counter intuitive, but is required to light a BLF
3185 * AST_DEVICE_INUSE indicates no members are available.
3186 * AST_DEVICE_NOT_INUSE indicates a member is available.
3187 */
3189}
3190
3191static void clear_queue(struct call_queue *q)
3192{
3193 q->holdtime = 0;
3194 q->callscompleted = 0;
3195 q->callsabandoned = 0;
3196 q->callscompletedinsl = 0;
3197 q->callsabandonedinsl = 0;
3198 q->talktime = 0;
3199
3200 if (q->members) {
3201 struct member *mem;
3202 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0);
3203 while ((mem = ao2_iterator_next(&mem_iter))) {
3204 mem->calls = 0;
3205 mem->callcompletedinsl = 0;
3206 mem->lastcall = 0;
3207 mem->starttime = 0;
3208 ao2_ref(mem, -1);
3209 }
3210 ao2_iterator_destroy(&mem_iter);
3211 }
3212}
3213
3214/*!
3215 * \brief Change queue penalty by adding rule.
3216 *
3217 * Check rule for errors with time or formatting, see if rule is relative to rest
3218 * of queue, iterate list of rules to find correct insertion point, insert and return.
3219 * \retval -1 on failure
3220 * \retval 0 on success
3221 * \note Call this with the rule_lists locked
3222*/
3223static int insert_penaltychange(const char *list_name, const char *content, const int linenum)
3224{
3225 char *timestr, *maxstr, *minstr, *raisestr, *contentdup;
3226 struct penalty_rule *rule = NULL, *rule_iter;
3227 struct rule_list *rl_iter;
3228 int penaltychangetime, inserted = 0;
3229
3230 if (!(rule = ast_calloc(1, sizeof(*rule)))) {
3231 return -1;
3232 }
3233
3234 contentdup = ast_strdupa(content);
3235
3236 if (!(maxstr = strchr(contentdup, ','))) {
3237 ast_log(LOG_WARNING, "Improperly formatted penaltychange rule at line %d. Ignoring.\n", linenum);
3238 ast_free(rule);
3239 return -1;
3240 }
3241
3242 *maxstr++ = '\0';
3243 if ((minstr = strchr(maxstr,','))) {
3244 *minstr++ = '\0';
3245 if ((raisestr = strchr(minstr,','))) {
3246 *raisestr++ = '\0';
3247 }
3248 } else {
3249 raisestr = NULL;
3250 }
3251
3252 timestr = contentdup;
3253 if ((penaltychangetime = atoi(timestr)) < 0) {
3254 ast_log(LOG_WARNING, "Improper time parameter specified for penaltychange rule at line %d. Ignoring.\n", linenum);
3255 ast_free(rule);
3256 return -1;
3257 }
3258
3259 rule->time = penaltychangetime;
3260
3261 /* The last check will evaluate true if either no penalty change is indicated for a given rule
3262 * OR if a min penalty change is indicated but no max penalty change is */
3263 if (*maxstr == '+' || *maxstr == '-' || *maxstr == '\0') {
3264 rule->max_relative = 1;
3265 }
3266
3267 rule->max_value = atoi(maxstr);
3268
3269 if (!ast_strlen_zero(minstr)) {
3270 if (*minstr == '+' || *minstr == '-') {
3271 rule->min_relative = 1;
3272 }
3273 rule->min_value = atoi(minstr);
3274 } else { /*there was no minimum specified, so assume this means no change*/
3275 rule->min_relative = 1;
3276 }
3277
3278 if (!ast_strlen_zero(raisestr)) {
3279 rule->raise_respect_min = 0; /* Initialize to 0 */
3280 if (*raisestr == 'r') {
3281 rule->raise_respect_min = 1; /* Set the flag */
3282 raisestr++;
3283 }
3284 if (*raisestr == '+' || *raisestr == '-') {
3285 rule->raise_relative = 1;
3286 }
3287 rule->raise_value = atoi(raisestr);
3288 } else { /*there was no raise specified, so assume this means no change*/
3289 rule->raise_relative = 1;
3290 }
3291
3292 /*We have the rule made, now we need to insert it where it belongs*/
3293 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list){
3294 if (strcasecmp(rl_iter->name, list_name)) {
3295 continue;
3296 }
3297
3298 AST_LIST_TRAVERSE_SAFE_BEGIN(&rl_iter->rules, rule_iter, list) {
3299 if (rule->time < rule_iter->time) {
3301 inserted = 1;
3302 break;
3303 }
3304 }
3306
3307 if (!inserted) {
3308 AST_LIST_INSERT_TAIL(&rl_iter->rules, rule, list);
3309 inserted = 1;
3310 }
3311
3312 break;
3313 }
3314
3315 if (!inserted) {
3316 ast_log(LOG_WARNING, "Unknown rule list name %s; ignoring.\n", list_name);
3317 ast_free(rule);
3318 return -1;
3319 }
3320 return 0;
3321}
3322
3323/*!
3324 * \brief Load queue rules from realtime.
3325 *
3326 * Check rule for errors with time or formatting, see if rule is relative to rest
3327 * of queue, iterate list of rules to find correct insertion point, insert and return.
3328 * \retval -1 on failure
3329 * \retval 0 on success
3330 * \note Call this with the rule_lists locked
3331*/
3332static int load_realtime_rules(void)
3333{
3334 struct ast_config *cfg;
3335 struct rule_list *rl_iter, *new_rl;
3336 struct penalty_rule *pr_iter;
3337 char *rulecat = NULL;
3338
3339 if (!ast_check_realtime("queue_rules")) {
3340 ast_log(LOG_WARNING, "Missing \"queue_rules\" in extconfig.conf\n");
3341 return 0;
3342 }
3343 if (!(cfg = ast_load_realtime_multientry("queue_rules", "rule_name LIKE", "%", SENTINEL))) {
3344 ast_log(LOG_WARNING, "Failed to load queue rules from realtime\n");
3345 return 0;
3346 }
3347 while ((rulecat = ast_category_browse(cfg, rulecat))) {
3348 const char *timestr, *maxstr, *minstr, *raisestr, *rule_name;
3349 int penaltychangetime, rule_exists = 0, inserted = 0;
3350 int max_penalty = 0, min_penalty = 0, raise_penalty = 0;
3351 int min_relative = 0, max_relative = 0, raise_relative = 0;
3352 struct penalty_rule *new_penalty_rule = NULL;
3353
3354 rule_name = ast_variable_retrieve(cfg, rulecat, "rule_name");
3355 if (ast_strlen_zero(rule_name)) {
3356 continue;
3357 }
3358
3359 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) {
3360 if (!(strcasecmp(rl_iter->name, rule_name))) {
3361 rule_exists = 1;
3362 new_rl = rl_iter;
3363 break;
3364 }
3365 }
3366 if (!rule_exists) {
3367 if (!(new_rl = ast_calloc(1, sizeof(*new_rl)))) {
3368 ast_config_destroy(cfg);
3369 return -1;
3370 }
3371 ast_copy_string(new_rl->name, rule_name, sizeof(new_rl->name));
3373 }
3374 timestr = ast_variable_retrieve(cfg, rulecat, "time");
3375 if (!(timestr) || sscanf(timestr, "%30d", &penaltychangetime) != 1) {
3376 ast_log(LOG_NOTICE, "Failed to parse time (%s) for one of the %s rules, skipping it\n",
3377 (ast_strlen_zero(timestr) ? "invalid value" : timestr), rule_name);
3378 continue;
3379 }
3380 if (!(new_penalty_rule = ast_calloc(1, sizeof(*new_penalty_rule)))) {
3381 ast_config_destroy(cfg);
3382 return -1;
3383 }
3384 if (!(maxstr = ast_variable_retrieve(cfg, rulecat, "max_penalty")) ||
3385 ast_strlen_zero(maxstr) || sscanf(maxstr, "%30d", &max_penalty) != 1) {
3386 max_penalty = 0;
3387 max_relative = 1;
3388 } else {
3389 if (*maxstr == '+' || *maxstr == '-') {
3390 max_relative = 1;
3391 }
3392 }
3393 if (!(minstr = ast_variable_retrieve(cfg, rulecat, "min_penalty")) ||
3394 ast_strlen_zero(minstr) || sscanf(minstr, "%30d", &min_penalty) != 1) {
3395 min_penalty = 0;
3396 min_relative = 1;
3397 } else {
3398 if (*minstr == '+' || *minstr == '-') {
3399 min_relative = 1;
3400 }
3401 }
3402 if (!(raisestr = ast_variable_retrieve(cfg, rulecat, "raise_penalty")) ||
3403 ast_strlen_zero(raisestr) ) {
3404 raise_penalty = 0;
3405 raise_relative = 1;
3406 } else {
3407 if (*raisestr == 'r') {
3408 new_penalty_rule->raise_respect_min = 1;
3409 raisestr++;
3410 } else {
3411 new_penalty_rule->raise_respect_min = 0;
3412 }
3413 if (*raisestr == '+' || *raisestr == '-') {
3414 raise_relative = 1;
3415 }
3416 if (sscanf(raisestr, "%30d", &raise_penalty) != 1) {
3417 raise_penalty = 0;
3418 raise_relative = 1;
3419 }
3420 }
3421 new_penalty_rule->time = penaltychangetime;
3422 new_penalty_rule->max_relative = max_relative;
3423 new_penalty_rule->max_value = max_penalty;
3424 new_penalty_rule->min_relative = min_relative;
3425 new_penalty_rule->min_value = min_penalty;
3426 new_penalty_rule->raise_relative = raise_relative;
3427 new_penalty_rule->raise_value = raise_penalty;
3428 AST_LIST_TRAVERSE_SAFE_BEGIN(&new_rl->rules, pr_iter, list) {
3429 if (new_penalty_rule->time < pr_iter->time) {
3430 AST_LIST_INSERT_BEFORE_CURRENT(new_penalty_rule, list);
3431 inserted = 1;
3432 }
3433 }
3435 if (!inserted) {
3436 AST_LIST_INSERT_TAIL(&new_rl->rules, new_penalty_rule, list);
3437 }
3438 }
3439
3440 ast_config_destroy(cfg);
3441 return 0;
3442}
3443
3444static void parse_empty_options(const char *value, enum empty_conditions *empty, int joinempty)
3445{
3446 char *value_copy = ast_strdupa(value);
3447 char *option = NULL;
3448 while ((option = strsep(&value_copy, ","))) {
3449 if (!strcasecmp(option, "paused")) {
3450 *empty |= QUEUE_EMPTY_PAUSED;
3451 } else if (!strcasecmp(option, "penalty")) {
3452 *empty |= QUEUE_EMPTY_PENALTY;
3453 } else if (!strcasecmp(option, "inuse")) {
3454 *empty |= QUEUE_EMPTY_INUSE;
3455 } else if (!strcasecmp(option, "ringing")) {
3456 *empty |= QUEUE_EMPTY_RINGING;
3457 } else if (!strcasecmp(option, "invalid")) {
3458 *empty |= QUEUE_EMPTY_INVALID;
3459 } else if (!strcasecmp(option, "wrapup")) {
3460 *empty |= QUEUE_EMPTY_WRAPUP;
3461 } else if (!strcasecmp(option, "unavailable")) {
3462 *empty |= QUEUE_EMPTY_UNAVAILABLE;
3463 } else if (!strcasecmp(option, "unknown")) {
3464 *empty |= QUEUE_EMPTY_UNKNOWN;
3465 } else if (!strcasecmp(option, "loose")) {
3467 } else if (!strcasecmp(option, "strict")) {
3469 } else if ((ast_false(option) && joinempty) || (ast_true(option) && !joinempty)) {
3471 } else if ((ast_false(option) && !joinempty) || (ast_true(option) && joinempty)) {
3472 *empty = 0;
3473 } else {
3474 ast_log(LOG_WARNING, "Unknown option %s for '%s'\n", option, joinempty ? "joinempty" : "leavewhenempty");
3475 }
3476 }
3477}
3478
3479/*! \brief Configure a queue parameter.
3480 *
3481 * The failunknown flag is set for config files (and static realtime) to show
3482 * errors for unknown parameters. It is cleared for dynamic realtime to allow
3483 * extra fields in the tables.
3484 * \note For error reporting, line number is passed for .conf static configuration,
3485 * for Realtime queues, linenum is -1.
3486*/
3487static void queue_set_param(struct call_queue *q, const char *param, const char *val, int linenum, int failunknown)
3488{
3489 if (!strcasecmp(param, "musicclass") ||
3490 !strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
3491 ast_string_field_set(q, moh, val);
3492 } else if (!strcasecmp(param, "announce")) {
3493 ast_string_field_set(q, announce, val);
3494 } else if (!strcasecmp(param, "context")) {
3495 ast_string_field_set(q, context, val);
3496 } else if (!strcasecmp(param, "timeout")) {
3497 q->timeout = atoi(val);
3498 if (q->timeout < 0) {
3500 }
3501 } else if (!strcasecmp(param, "ringinuse")) {
3502 q->ringinuse = ast_true(val);
3503 } else if (!strcasecmp(param, "setinterfacevar")) {
3505 } else if (!strcasecmp(param, "setqueuevar")) {
3506 q->setqueuevar = ast_true(val);
3507 } else if (!strcasecmp(param, "setqueueentryvar")) {
3509 } else if (!strcasecmp(param, "monitor-format")) {
3510 ast_copy_string(q->monfmt, val, sizeof(q->monfmt));
3511 } else if (!strcasecmp(param, "membergosub")) {
3512 ast_string_field_set(q, membergosub, val);
3513 } else if (!strcasecmp(param, "queue-youarenext")) {
3514 ast_string_field_set(q, sound_next, val);
3515 } else if (!strcasecmp(param, "queue-thereare")) {
3516 ast_string_field_set(q, sound_thereare, val);
3517 } else if (!strcasecmp(param, "queue-callswaiting")) {
3518 ast_string_field_set(q, sound_calls, val);
3519 } else if (!strcasecmp(param, "queue-quantity1")) {
3520 ast_string_field_set(q, queue_quantity1, val);
3521 } else if (!strcasecmp(param, "queue-quantity2")) {
3522 ast_string_field_set(q, queue_quantity2, val);
3523 } else if (!strcasecmp(param, "queue-holdtime")) {
3524 ast_string_field_set(q, sound_holdtime, val);
3525 } else if (!strcasecmp(param, "queue-minutes")) {
3526 ast_string_field_set(q, sound_minutes, val);
3527 } else if (!strcasecmp(param, "queue-minute")) {
3528 ast_string_field_set(q, sound_minute, val);
3529 } else if (!strcasecmp(param, "queue-seconds")) {
3530 ast_string_field_set(q, sound_seconds, val);
3531 } else if (!strcasecmp(param, "queue-thankyou")) {
3532 ast_string_field_set(q, sound_thanks, val);
3533 } else if (!strcasecmp(param, "queue-callerannounce")) {
3534 ast_string_field_set(q, sound_callerannounce, val);
3535 } else if (!strcasecmp(param, "queue-reporthold")) {
3536 ast_string_field_set(q, sound_reporthold, val);
3537 } else if (!strcasecmp(param, "announce-frequency")) {
3538 q->announcefrequency = atoi(val);
3539 } else if (!strcasecmp(param, "announce-to-first-user")) {
3541 } else if (!strcasecmp(param, "min-announce-frequency")) {
3542 q->minannouncefrequency = atoi(val);
3543 ast_debug(1, "%s=%s for queue '%s'\n", param, val, q->name);
3544 } else if (!strcasecmp(param, "announce-round-seconds")) {
3545 q->roundingseconds = atoi(val);
3546 /* Rounding to any other values just doesn't make sense... */
3547 if (!(q->roundingseconds == 0 || q->roundingseconds == 5 || q->roundingseconds == 10
3548 || q->roundingseconds == 15 || q->roundingseconds == 20 || q->roundingseconds == 30)) {
3549 if (linenum >= 0) {
3550 ast_log(LOG_WARNING, "'%s' isn't a valid value for %s "
3551 "using 0 instead for queue '%s' at line %d of queues.conf\n",
3552 val, param, q->name, linenum);
3553 } else {
3554 ast_log(LOG_WARNING, "'%s' isn't a valid value for %s "
3555 "using 0 instead for queue '%s'\n", val, param, q->name);
3556 }
3557 q->roundingseconds=0;
3558 }
3559 } else if (!strcasecmp(param, "announce-holdtime")) {
3560 if (!strcasecmp(val, "once")) {
3562 } else if (ast_true(val)) {
3564 } else {
3565 q->announceholdtime = 0;
3566 }
3567 } else if (!strcasecmp(param, "announce-position")) {
3568 if (!strcasecmp(val, "limit")) {
3570 } else if (!strcasecmp(val, "more")) {
3572 } else if (ast_true(val)) {
3574 } else {
3576 }
3577 } else if (!strcasecmp(param, "announce-position-only-up")) {
3579 } else if (!strcasecmp(param, "announce-position-limit")) {
3580 q->announcepositionlimit = atoi(val);
3581 } else if (!strcasecmp(param, "periodic-announce")) {
3582 if (strchr(val, ',')) {
3583 char *s, *buf = ast_strdupa(val);
3584 unsigned int i = 0;
3585
3586 while ((s = strsep(&buf, ",|"))) {
3587 if (!q->sound_periodicannounce[i]) {
3589 }
3590 ast_str_set(&q->sound_periodicannounce[i], 0, "%s", s);
3591 i++;
3592 if (i == MAX_PERIODIC_ANNOUNCEMENTS) {
3593 break;
3594 }
3595 }
3596 q->numperiodicannounce = i;
3597 } else {
3598 ast_str_set(&q->sound_periodicannounce[0], 0, "%s", val);
3599 q->numperiodicannounce = 1;
3600 }
3601 } else if (!strcasecmp(param, "periodic-announce-startdelay")) {
3603 } else if (!strcasecmp(param, "periodic-announce-frequency")) {
3604 q->periodicannouncefrequency = atoi(val);
3605 } else if (!strcasecmp(param, "relative-periodic-announce")) {
3607 } else if (!strcasecmp(param, "random-periodic-announce")) {
3609 } else if (!strcasecmp(param, "retry")) {
3610 q->retry = atoi(val);
3611 if (q->retry <= 0) {
3612 q->retry = DEFAULT_RETRY;
3613 }
3614 } else if (!strcasecmp(param, "wrapuptime")) {
3615 q->wrapuptime = atoi(val);
3616 } else if (!strcasecmp(param, "penaltymemberslimit")) {
3617 if ((sscanf(val, "%10d", &q->penaltymemberslimit) != 1)) {
3618 q->penaltymemberslimit = 0;
3619 }
3620 } else if (!strcasecmp(param, "autofill")) {
3621 q->autofill = ast_true(val);
3622 } else if (!strcasecmp(param, "autopause")) {
3624 } else if (!strcasecmp(param, "autopausedelay")) {
3625 q->autopausedelay = atoi(val);
3626 } else if (!strcasecmp(param, "autopausebusy")) {
3628 } else if (!strcasecmp(param, "autopauseunavail")) {
3630 } else if (!strcasecmp(param, "maxlen")) {
3631 q->maxlen = atoi(val);
3632 if (q->maxlen < 0) {
3633 q->maxlen = 0;
3634 }
3635 } else if (!strcasecmp(param, "servicelevel")) {
3636 q->servicelevel= atoi(val);
3637 } else if (!strcasecmp(param, "strategy")) {
3638 int strategy;
3639
3640 /* We are a static queue and already have set this, no need to do it again */
3641 if (failunknown) {
3642 return;
3643 }
3645 if (strategy < 0) {
3646 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n",
3647 val, q->name);
3649 }
3650 if (strategy == q->strategy) {
3651 return;
3652 }
3654 ast_log(LOG_WARNING, "Changing to the linear strategy currently requires asterisk to be restarted.\n");
3655 return;
3656 }
3657 q->strategy = strategy;
3658 } else if (!strcasecmp(param, "joinempty")) {
3660 } else if (!strcasecmp(param, "leavewhenempty")) {
3662 } else if (!strcasecmp(param, "reportholdtime")) {
3664 } else if (!strcasecmp(param, "memberdelay")) {
3665 q->memberdelay = atoi(val);
3666 } else if (!strcasecmp(param, "weight")) {
3667 q->weight = atoi(val);
3668 } else if (!strcasecmp(param, "timeoutrestart")) {
3670 } else if (!strcasecmp(param, "defaultrule")) {
3671 ast_string_field_set(q, defaultrule, val);
3672 } else if (!strcasecmp(param, "timeoutpriority")) {
3673 if (!strcasecmp(val, "conf")) {
3675 } else {
3677 }
3678 } else if (!strcasecmp(param, "log-restricted-caller-id")) {
3680 } else if (failunknown) {
3681 if (linenum >= 0) {
3682 ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s at line %d of queues.conf\n",
3683 q->name, param, linenum);
3684 } else {
3685 ast_log(LOG_WARNING, "Unknown keyword in queue '%s': %s\n", q->name, param);
3686 }
3687 }
3688}
3689
3690
3691#define QUEUE_PAUSED_DEVSTATE AST_DEVICE_INUSE
3692#define QUEUE_UNPAUSED_DEVSTATE AST_DEVICE_NOT_INUSE
3693#define QUEUE_UNKNOWN_PAUSED_DEVSTATE AST_DEVICE_NOT_INUSE
3694
3695/*! \internal
3696 * \brief If adding a single new member to a queue, use this function instead of ao2_linking.
3697 * This adds round robin queue position data for a fresh member as well as links it.
3698 * \param queue Which queue the member is being added to
3699 * \param mem Which member is being added to the queue
3700 */
3701static void member_add_to_queue(struct call_queue *queue, struct member *mem)
3702{
3703 ao2_lock(queue->members);
3704 mem->queuepos = ao2_container_count(queue->members);
3705 ao2_link(queue->members, mem);
3707 AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", queue->name, mem->interface);
3708 ao2_unlock(queue->members);
3709}
3710
3711/*! \internal
3712 * \brief If removing a single member from a queue, use this function instead of ao2_unlinking.
3713 * This will perform round robin queue position reordering for the remaining members.
3714 * \param queue Which queue the member is being removed from
3715 * \param mem Which member is being removed from the queue
3716 */
3717static void member_remove_from_queue(struct call_queue *queue, struct member *mem)
3718{
3720 ao2_lock(queue->members);
3723 ao2_unlink(queue->members, mem);
3724 ao2_unlock(queue->members);
3725}
3726
3727/*!
3728 * \brief Find rt member record to update otherwise create one.
3729 *
3730 * Search for member in queue, if found update penalty/paused state,
3731 * if no member exists create one flag it as a RT member and add to queue member list.
3732*/
3733static void rt_handle_member_record(struct call_queue *q, char *category, struct ast_config *member_config)
3734{
3735 struct member *m;
3736 struct ao2_iterator mem_iter;
3737 int penalty = 0;
3738 int paused = 0;
3739 int found = 0;
3740 int wrapuptime = 0;
3741 int ringinuse = q->ringinuse;
3742
3743 const char *config_val;
3744 const char *interface = ast_variable_retrieve(member_config, category, "interface");
3745 const char *rt_uniqueid = ast_variable_retrieve(member_config, category, "uniqueid");
3746 const char *membername = S_OR(ast_variable_retrieve(member_config, category, "membername"), interface);
3747 const char *state_interface = S_OR(ast_variable_retrieve(member_config, category, "state_interface"), interface);
3748 const char *penalty_str = ast_variable_retrieve(member_config, category, "penalty");
3749 const char *paused_str = ast_variable_retrieve(member_config, category, "paused");
3750 const char *wrapuptime_str = ast_variable_retrieve(member_config, category, "wrapuptime");
3751 const char *reason_paused = ast_variable_retrieve(member_config, category, "reason_paused");
3752
3753 if (ast_strlen_zero(rt_uniqueid)) {
3754 ast_log(LOG_WARNING, "Realtime field 'uniqueid' is empty for member %s\n",
3755 S_OR(membername, "NULL"));
3756 return;
3757 }
3758
3759 if (ast_strlen_zero(interface)) {
3760 ast_log(LOG_WARNING, "Realtime field 'interface' is empty for member %s\n",
3761 S_OR(membername, "NULL"));
3762 return;
3763 }
3764
3765 if (penalty_str) {
3766 penalty = atoi(penalty_str);
3767 if ((penalty < 0) && negative_penalty_invalid) {
3768 return;
3769 } else if (penalty < 0) {
3770 penalty = 0;
3771 }
3772 }
3773
3774 if (paused_str) {
3775 paused = atoi(paused_str);
3776 if (paused < 0) {
3777 paused = 0;
3778 }
3779 }
3780
3781 if (wrapuptime_str) {
3782 wrapuptime = atoi(wrapuptime_str);
3783 if (wrapuptime < 0) {
3784 wrapuptime = 0;
3785 }
3786 }
3787
3788 if ((config_val = ast_variable_retrieve(member_config, category, realtime_ringinuse_field))) {
3789 if (ast_true(config_val)) {
3790 ringinuse = 1;
3791 } else if (ast_false(config_val)) {
3792 ringinuse = 0;
3793 } else {
3794 ast_log(LOG_WARNING, "Invalid value of '%s' field for %s in queue '%s'\n", realtime_ringinuse_field, interface, q->name);
3795 }
3796 }
3797
3798 /* Find member by realtime uniqueid and update */
3799 mem_iter = ao2_iterator_init(q->members, 0);
3800 while ((m = ao2_iterator_next(&mem_iter))) {
3801 if (!strcasecmp(m->rt_uniqueid, rt_uniqueid)) {
3802 m->dead = 0; /* Do not delete this one. */
3803 ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid));
3804 if (paused_str) {
3805 m->paused = paused;
3806 if (paused && m->lastpause == 0) {
3807 time(&m->lastpause); /* XXX: Should this come from realtime? */
3808 }
3810 AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, m->interface);
3811 }
3812 if (strcasecmp(state_interface, m->state_interface)) {
3813 ast_copy_string(m->state_interface, state_interface, sizeof(m->state_interface));
3814 }
3815 m->penalty = penalty;
3816 m->ringinuse = ringinuse;
3817 m->wrapuptime = wrapuptime;
3819 ast_copy_string(m->reason_paused, S_OR(reason_paused, ""), sizeof(m->reason_paused));
3820 }
3821 found = 1;
3822 ao2_ref(m, -1);
3823 break;
3824 }
3825 ao2_ref(m, -1);
3826 }
3827 ao2_iterator_destroy(&mem_iter);
3828
3829 /* Create a new member */
3830 if (!found) {
3831 if ((m = create_queue_member(interface, membername, penalty, paused, state_interface, ringinuse, wrapuptime))) {
3832 m->dead = 0;
3833 m->realtime = 1;
3834 ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid));
3835 if (!ast_strlen_zero(reason_paused)) {
3836 ast_copy_string(m->reason_paused, reason_paused, sizeof(m->reason_paused));
3837 }
3839 ast_queue_log(q->name, "REALTIME", m->interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
3840 } else {
3841 ast_queue_log(q->name, "REALTIME", m->membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
3842 }
3843 member_add_to_queue(q, m);
3844 ao2_ref(m, -1);
3845 m = NULL;
3846 }
3847 }
3848}
3849
3850/*! \brief Iterate through queue's member list and delete them */
3851static void free_members(struct call_queue *q, int all)
3852{
3853 /* Free non-dynamic members */
3854 struct member *cur;
3855 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0);
3856
3857 while ((cur = ao2_iterator_next(&mem_iter))) {
3858 if (all || !cur->dynamic) {
3860 }
3861 ao2_ref(cur, -1);
3862 }
3863 ao2_iterator_destroy(&mem_iter);
3864}
3865
3866/*! \brief Free queue's member list then its string fields */
3867static void destroy_queue(void *obj)
3868{
3869 struct call_queue *q = obj;
3870 int i;
3871
3872 free_members(q, 1);
3874 for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
3875 if (q->sound_periodicannounce[i]) {
3877 }
3878 }
3879 ao2_ref(q->members, -1);
3880}
3881
3882static struct call_queue *alloc_queue(const char *queuename)
3883{
3884 struct call_queue *q;
3885
3886 if ((q = ao2_t_alloc(sizeof(*q), destroy_queue, "Allocate queue"))) {
3887 if (ast_string_field_init(q, 64)) {
3888 queue_t_unref(q, "String field allocation failed");
3889 return NULL;
3890 }
3891 ast_string_field_set(q, name, queuename);
3892 }
3893 return q;
3894}
3895
3896/*!
3897 * \brief Reload a single queue via realtime.
3898 *
3899 * Check for statically defined queue first, check if deleted RT queue,
3900 * check for new RT queue, if queue vars are not defined init them with defaults.
3901 * reload RT queue vars, set RT queue members dead and reload them, return finished queue.
3902 * \retval the queue,
3903 * \retval NULL if it doesn't exist.
3904 * \note Should be called with the "queues" container locked.
3905*/
3906static struct call_queue *find_queue_by_name_rt(const char *queuename, struct ast_variable *queue_vars, struct ast_config *member_config)
3907{
3908 struct ast_variable *v;
3909 struct call_queue *q, tmpq = {
3910 .name = queuename,
3911 };
3912 struct member *m;
3913 struct ao2_iterator mem_iter;
3914 char *category = NULL;
3915 const char *tmp_name;
3916 char *tmp;
3917 char tmpbuf[64]; /* Must be longer than the longest queue param name. */
3918
3919 /* Static queues override realtime. */
3920 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Check if static queue exists"))) {
3921 ao2_lock(q);
3922 if (!q->realtime) {
3923 if (q->dead) {
3924 ao2_unlock(q);
3925 queue_t_unref(q, "Queue is dead; can't return it");
3926 return NULL;
3927 }
3928 ast_log(LOG_WARNING, "Static queue '%s' already exists. Not loading from realtime\n", q->name);
3929 ao2_unlock(q);
3930 return q;
3931 }
3932 } else if (!member_config) {
3933 /* Not found in the list, and it's not realtime ... */
3934 return NULL;
3935 }
3936 /* Check if queue is defined in realtime. */
3937 if (!queue_vars) {
3938 /* Delete queue from in-core list if it has been deleted in realtime. */
3939 if (q) {
3940 /*! \note Hmm, can't seem to distinguish a DB failure from a not
3941 found condition... So we might delete an in-core queue
3942 in case of DB failure. */
3943 ast_debug(1, "Queue %s not found in realtime.\n", queuename);
3944
3945 q->dead = 1;
3946 /* Delete if unused (else will be deleted when last caller leaves). */
3947 queues_t_unlink(queues, q, "Unused; removing from container");
3948 ao2_unlock(q);
3949 queue_t_unref(q, "Queue is dead; can't return it");
3950 }
3951 return NULL;
3952 }
3953
3954 /* Create a new queue if an in-core entry does not exist yet. */
3955 if (!q) {
3956 struct ast_variable *tmpvar = NULL;
3957 if (!(q = alloc_queue(queuename))) {
3958 return NULL;
3959 }
3960 ao2_lock(q);
3961 clear_queue(q);
3962 q->realtime = 1;
3963 /*Before we initialize the queue, we need to set the strategy, so that linear strategy
3964 * will allocate the members properly
3965 */
3966 for (tmpvar = queue_vars; tmpvar; tmpvar = tmpvar->next) {
3967 if (!strcasecmp(tmpvar->name, "strategy")) {
3968 q->strategy = strat2int(tmpvar->value);
3969 if (q->strategy < 0) {
3970 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n",
3971 tmpvar->value, q->name);
3973 }
3974 break;
3975 }
3976 }
3977 /* We traversed all variables and didn't find a strategy */
3978 if (!tmpvar) {
3980 }
3981 queues_t_link(queues, q, "Add queue to container");
3982 }
3983 init_queue(q); /* Ensure defaults for all parameters not set explicitly. */
3984
3985 memset(tmpbuf, 0, sizeof(tmpbuf));
3986 for (v = queue_vars; v; v = v->next) {
3987 /* Convert to dashes `-' from underscores `_' as the latter are more SQL friendly. */
3988 if (strchr(v->name, '_')) {
3989 ast_copy_string(tmpbuf, v->name, sizeof(tmpbuf));
3990 tmp_name = tmpbuf;
3991 tmp = tmpbuf;
3992 while ((tmp = strchr(tmp, '_'))) {
3993 *tmp++ = '-';
3994 }
3995 } else {
3996 tmp_name = v->name;
3997 }
3998
3999 /* NULL values don't get returned from realtime; blank values should
4000 * still get set. If someone doesn't want a value to be set, they
4001 * should set the realtime column to NULL, not blank. */
4002 queue_set_param(q, tmp_name, v->value, -1, 0);
4003 }
4004
4005 /* Temporarily set realtime members dead so we can detect deleted ones. */
4006 mem_iter = ao2_iterator_init(q->members, 0);
4007 while ((m = ao2_iterator_next(&mem_iter))) {
4008 if (m->realtime) {
4009 m->dead = 1;
4010 }
4011 ao2_ref(m, -1);
4012 }
4013 ao2_iterator_destroy(&mem_iter);
4014
4015 while ((category = ast_category_browse(member_config, category))) {
4016 rt_handle_member_record(q, category, member_config);
4017 }
4018
4019 /* Delete all realtime members that have been deleted in DB. */
4020 mem_iter = ao2_iterator_init(q->members, 0);
4021 while ((m = ao2_iterator_next(&mem_iter))) {
4022 if (m->dead) {
4024 ast_queue_log(q->name, "REALTIME", m->interface, "REMOVEMEMBER", "%s", "");
4025 } else {
4026 ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
4027 }
4029 }
4030 ao2_ref(m, -1);
4031 }
4032 ao2_iterator_destroy(&mem_iter);
4033
4034 ao2_unlock(q);
4035
4036 return q;
4037}
4038
4039/*!
4040 * note */
4041
4042/*!
4043 * \internal
4044 * \brief Returns reference to the named queue. If the queue is realtime, it will load the queue as well.
4045 * \param queuename - name of the desired queue
4046 *
4047 * \retval the queue
4048 * \retval NULL if it doesn't exist
4049 */
4050static struct call_queue *find_load_queue_rt_friendly(const char *queuename)
4051{
4052 struct ast_variable *queue_vars;
4053 struct ast_config *member_config = NULL;
4054 struct call_queue *q = NULL, tmpq = {
4055 .name = queuename,
4056 };
4057 int prev_weight = 0;
4058
4059 /* Find the queue in the in-core list first. */
4060 q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Look for queue in memory first");
4061
4062 if (!q || q->realtime) {
4063 /*! \note Load from realtime before taking the "queues" container lock, to avoid blocking all
4064 queue operations while waiting for the DB.
4065
4066 This will be two separate database transactions, so we might
4067 see queue parameters as they were before another process
4068 changed the queue and member list as it was after the change.
4069 Thus we might see an empty member list when a queue is
4070 deleted. In practise, this is unlikely to cause a problem. */
4071
4072 queue_vars = ast_load_realtime("queues", "name", queuename, SENTINEL);
4073 if (queue_vars) {
4074 member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", queuename, SENTINEL);
4075 if (!member_config) {
4076 ast_debug(1, "No queue_members defined in config extconfig.conf\n");
4077 member_config = ast_config_new();
4078 }
4079 }
4080 if (q) {
4081 prev_weight = q->weight ? 1 : 0;
4082 queue_t_unref(q, "Need to find realtime queue");
4083 }
4084
4085 q = find_queue_by_name_rt(queuename, queue_vars, member_config);
4086 ast_config_destroy(member_config);
4087 ast_variables_destroy(queue_vars);
4088
4089 /* update the use_weight value if the queue's has gained or lost a weight */
4090 if (q) {
4091 if (!q->weight && prev_weight) {
4093 }
4094 if (q->weight && !prev_weight) {
4096 }
4097 }
4098 /* Other cases will end up with the proper value for use_weight */
4099 } else {
4101 }
4102 return q;
4103}
4104
4105/*!
4106 * \internal
4107 * \brief Load queues and members from realtime.
4108 *
4109 * \param queuename - name of the desired queue to load or empty if need to load all queues
4110*/
4111static void load_realtime_queues(const char *queuename)
4112{
4113 struct ast_config *cfg = NULL;
4114 char *category = NULL;
4115 const char *name = NULL;
4116 struct call_queue *q = NULL;
4117
4118 if (!ast_check_realtime("queues")) {
4119 return;
4120 }
4121
4122 if (ast_strlen_zero(queuename)) {
4123 if ((cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL))) {
4124 while ((category = ast_category_browse(cfg, category))) {
4125 name = ast_variable_retrieve(cfg, category, "name");
4127 queue_unref(q);
4128 }
4129 }
4130 ast_config_destroy(cfg);
4131 }
4132 } else {
4133 if ((q = find_load_queue_rt_friendly(queuename))) {
4134 queue_unref(q);
4135 }
4136 }
4137}
4138
4139static int update_realtime_member_field(struct member *mem, const char *queue_name, const char *field, const char *value)
4140{
4141 int ret = -1;
4142
4143 if (ast_strlen_zero(mem->rt_uniqueid)) {
4144 return ret;
4145 }
4146
4147 if ((ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, field, value, SENTINEL)) >= 0) {
4148 ret = 0;
4149 }
4150
4151 return ret;
4152}
4153
4154
4156{
4157 struct ast_config *member_config = NULL;
4158 struct member *m;
4159 char *category = NULL;
4160 struct ao2_iterator mem_iter;
4161
4162 if (!(member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", q->name , SENTINEL))) {
4163 /* This queue doesn't have realtime members. If the queue still has any realtime
4164 * members in memory, they need to be removed.
4165 */
4166 ao2_lock(q);
4167 mem_iter = ao2_iterator_init(q->members, 0);
4168 while ((m = ao2_iterator_next(&mem_iter))) {
4169 if (m->realtime) {
4171 }
4172 ao2_ref(m, -1);
4173 }
4174 ao2_iterator_destroy(&mem_iter);
4175 ast_debug(3, "Queue %s has no realtime members defined. No need for update\n", q->name);
4176 ao2_unlock(q);
4177 return;
4178 }
4179
4180 ao2_lock(q);
4181
4182 /* Temporarily set realtime members dead so we can detect deleted ones.*/
4183 mem_iter = ao2_iterator_init(q->members, 0);
4184 while ((m = ao2_iterator_next(&mem_iter))) {
4185 if (m->realtime) {
4186 m->dead = 1;
4187 }
4188 ao2_ref(m, -1);
4189 }
4190 ao2_iterator_destroy(&mem_iter);
4191
4192 while ((category = ast_category_browse(member_config, category))) {
4193 rt_handle_member_record(q, category, member_config);
4194 }
4195
4196 /* Delete all realtime members that have been deleted in DB. */
4197 mem_iter = ao2_iterator_init(q->members, 0);
4198 while ((m = ao2_iterator_next(&mem_iter))) {
4199 if (m->dead) {
4201 ast_queue_log(q->name, "REALTIME", m->interface, "REMOVEMEMBER", "%s", "");
4202 } else {
4203 ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
4204 }
4206 }
4207 ao2_ref(m, -1);
4208 }
4209 ao2_iterator_destroy(&mem_iter);
4210 ao2_unlock(q);
4211 ast_config_destroy(member_config);
4212}
4213
4214static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason, int position)
4215{
4216 struct call_queue *q;
4217 struct queue_ent *cur, *prev = NULL;
4218 int res = -1;
4219 int pos = 0;
4220 int inserted = 0;
4221
4223 return res;
4224 }
4225 ao2_lock(q);
4226
4227 /* This is our one */
4228 if (q->joinempty) {
4229 int status = 0;
4230 if ((status = get_member_status(q, qe->max_penalty, qe->min_penalty, qe->raise_penalty, q->joinempty, 0, qe->raise_respect_min))) {
4231 *reason = QUEUE_JOINEMPTY;
4232 ao2_unlock(q);
4233 queue_t_unref(q, "Done with realtime queue");
4234 return res;
4235 }
4236 }
4237 if (*reason == QUEUE_UNKNOWN && q->maxlen && (q->count >= q->maxlen)) {
4238 *reason = QUEUE_FULL;
4239 } else if (*reason == QUEUE_UNKNOWN) {
4240 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
4241
4242 /* There's space for us, put us at the right position inside
4243 * the queue.
4244 * Take into account the priority of the calling user */
4245 inserted = 0;
4246 prev = NULL;
4247 cur = q->head;
4248 while (cur) {
4249 /* We have higher priority than the current user, enter
4250 * before him, after all the other users with priority
4251 * higher or equal to our priority. */
4252 if ((!inserted) && (qe->prio > cur->prio)) {
4253 insert_entry(q, prev, qe, &pos);
4254 inserted = 1;
4255 }
4256 /* <= is necessary for the position comparison because it may not be possible to enter
4257 * at our desired position since higher-priority callers may have taken the position we want
4258 */
4259 if (!inserted && (qe->prio >= cur->prio) && position && (position <= pos + 1)) {
4260 insert_entry(q, prev, qe, &pos);
4261 inserted = 1;
4262 /*pos is incremented inside insert_entry, so don't need to add 1 here*/
4263 if (position < pos) {
4264 ast_log(LOG_NOTICE, "Asked to be inserted at position %d but forced into position %d due to higher priority callers\n", position, pos);
4265 }
4266 }
4267 cur->pos = ++pos;
4268 prev = cur;
4269 cur = cur->next;
4270 }
4271 /* No luck, join at the end of the queue */
4272 if (!inserted) {
4273 insert_entry(q, prev, qe, &pos);
4274 }
4275 ast_copy_string(qe->moh, q->moh, sizeof(qe->moh));
4276 ast_copy_string(qe->announce, q->announce, sizeof(qe->announce));
4277 ast_copy_string(qe->context, q->context, sizeof(qe->context));
4278 q->count++;
4279 if (q->count == 1) {
4281 }
4282
4283 res = 0;
4284
4285 blob = ast_json_pack("{s: s, s: i, s: i}",
4286 "Queue", q->name,
4287 "Position", qe->pos,
4288 "Count", q->count);
4290 ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, ast_channel_name(qe->chan), qe->pos );
4291 }
4292 ao2_unlock(q);
4293 queue_t_unref(q, "Done with realtime queue");
4294
4295 return res;
4296}
4297
4298static int play_file(struct ast_channel *chan, const char *filename)
4299{
4300 int res;
4301
4302 if (ast_strlen_zero(filename)) {
4303 return 0;
4304 }
4305
4306 if (!ast_fileexists(filename, NULL, ast_channel_language(chan))) {
4307 return 0;
4308 }
4309
4311
4313 if (!res) {
4315 }
4316
4318
4319 return res;
4320}
4321
4322/*!
4323 * \brief Check for valid exit from queue via goto
4324 * \retval 0 if failure
4325 * \retval 1 if successful
4326*/
4327static int valid_exit(struct queue_ent *qe, char digit)
4328{
4329 int digitlen = strlen(qe->digits);
4330
4331 /* Prevent possible buffer overflow */
4332 if (digitlen < sizeof(qe->digits) - 2) {
4333 qe->digits[digitlen] = digit;
4334 qe->digits[digitlen + 1] = '\0';
4335 } else {
4336 qe->digits[0] = '\0';
4337 return 0;
4338 }
4339
4340 /* If there's no context to goto, short-circuit */
4341 if (ast_strlen_zero(qe->context)) {
4342 return 0;
4343 }
4344
4345 /* If the extension is bad, then reset the digits to blank */
4346 if (!ast_canmatch_extension(qe->chan, qe->context, qe->digits, 1,
4348 qe->digits[0] = '\0';
4349 return 0;
4350 }
4351
4352 /* We have an exact match */
4353 if (!ast_goto_if_exists(qe->chan, qe->context, qe->digits, 1)) {
4354 qe->valid_digits = 1;
4355 /* Return 1 on a successful goto */
4356 return 1;
4357 }
4358
4359 return 0;
4360}
4361
4362static int say_position(struct queue_ent *qe, int ringing)
4363{
4364 int res = 0, say_thanks = 0;
4366 time_t now;
4367
4368 /* Let minannouncefrequency seconds pass between the start of each position announcement */
4369 time(&now);
4370 if ((now - qe->last_pos) < qe->parent->minannouncefrequency) {
4371 return 0;
4372 }
4373
4374 /* If either our position has changed, or we are over the freq timer, say position */
4375 if ((qe->last_pos_said == qe->pos) && ((now - qe->last_pos) < qe->parent->announcefrequency)) {
4376 return 0;
4377 }
4378
4379 /* Only announce if the caller's queue position has improved since last time */
4380 if (qe->parent->announceposition_only_up && qe->last_pos_said > 0 && qe->last_pos_said <= qe->pos) {
4381 return 0;
4382 }
4383
4384 if (ringing) {
4385 ast_indicate(qe->chan,-1);
4386 } else {
4387 ast_moh_stop(qe->chan);
4388 }
4389
4390 if (qe->parent->announceposition == ANNOUNCEPOSITION_YES ||
4391 qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN ||
4392 (qe->parent->announceposition == ANNOUNCEPOSITION_LIMIT &&
4393 qe->pos <= qe->parent->announcepositionlimit)) {
4394 say_thanks = 1;
4395 /* Say we're next, if we are */
4396 if (qe->pos == 1) {
4397 res = play_file(qe->chan, qe->parent->sound_next);
4398 if (!res) {
4399 goto posout;
4400 }
4401 /* Say there are more than N callers */
4402 } else if (qe->parent->announceposition == ANNOUNCEPOSITION_MORE_THAN && qe->pos > qe->parent->announcepositionlimit) {
4403 res = (
4404 play_file(qe->chan, qe->parent->queue_quantity1) ||
4405 ast_say_number(qe->chan, qe->parent->announcepositionlimit, AST_DIGIT_ANY,
4406 ast_channel_language(qe->chan), NULL) || /* Needs gender */
4407 play_file(qe->chan, qe->parent->queue_quantity2));
4408 /* Say there are currently N callers waiting */
4409 } else {
4410 res = (
4411 play_file(qe->chan, qe->parent->sound_thereare) ||
4412 ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY,
4413 ast_channel_language(qe->chan), "n") || /* Needs gender */
4414 play_file(qe->chan, qe->parent->sound_calls));
4415 }
4416 if (res) {
4417 goto playout;
4418 }
4419 }
4420 /* Round hold time to nearest minute */
4421 avgholdmins = labs(((qe->parent->holdtime + 30) - (now - qe->start)) / 60);
4422
4423 /* If they have specified a rounding then round the seconds as well */
4424 if (qe->parent->roundingseconds) {
4425 avgholdsecs = (labs(((qe->parent->holdtime + 30) - (now - qe->start))) - 60 * avgholdmins) / qe->parent->roundingseconds;
4426 avgholdsecs *= qe->parent->roundingseconds;
4427 } else {
4428 avgholdsecs = 0;
4429 }
4430
4431 ast_verb(3, "Hold time for %s is %ld minute(s) %ld seconds\n", qe->parent->name, avgholdmins, avgholdsecs);
4432
4433 /* If the hold time is >1 min, if it's enabled, and if it's not
4434 supposed to be only once and we have already said it, say it */
4435 if ((avgholdmins+avgholdsecs) > 0 && qe->parent->announceholdtime &&
4436 ((qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE && !qe->last_pos) ||
4437 !(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE))) {
4438 say_thanks = 1;
4439 res = play_file(qe->chan, qe->parent->sound_holdtime);
4440 if (res) {
4441 goto playout;
4442 }
4443
4444 if (avgholdmins >= 1) {
4446 if (res) {
4447 goto playout;
4448 }
4449
4450 if (avgholdmins == 1) {
4451 res = play_file(qe->chan, qe->parent->sound_minute);
4452 if (res) {
4453 goto playout;
4454 }
4455 } else {
4456 res = play_file(qe->chan, qe->parent->sound_minutes);
4457 if (res) {
4458 goto playout;
4459 }
4460 }
4461 }
4462 if (avgholdsecs >= 1) {
4464 if (res) {
4465 goto playout;
4466 }
4467
4468 res = play_file(qe->chan, qe->parent->sound_seconds);
4469 if (res) {
4470 goto playout;
4471 }
4472 }
4473 }
4474
4475posout:
4476 if (qe->parent->announceposition) {
4477 ast_verb(3, "Told %s in %s their queue position (which was %d)\n",
4478 ast_channel_name(qe->chan), qe->parent->name, qe->pos);
4479 }
4480 if (say_thanks) {
4481 res = play_file(qe->chan, qe->parent->sound_thanks);
4482 }
4483playout:
4484
4485 if ((res > 0 && !valid_exit(qe, res))) {
4486 res = 0;
4487 }
4488
4489 /* Set our last_pos indicators */
4490 qe->last_pos = now;
4491 qe->last_pos_said = qe->pos;
4492
4493 /* Don't restart music on hold if we're about to exit the caller from the queue */
4494 if (!res) {
4495 if (ringing) {
4497 } else {
4498 ast_moh_start(qe->chan, qe->moh, NULL);
4499 }
4500 }
4501 return res;
4502}
4503
4504static void recalc_holdtime(struct queue_ent *qe, int newholdtime)
4505{
4506 int oldvalue;
4507
4508 /* Calculate holdtime using an exponential average */
4509 /* Thanks to SRT for this contribution */
4510 /* 2^2 (4) is the filter coefficient; a higher exponent would give old entries more weight */
4511
4512 ao2_lock(qe->parent);
4513 if ((qe->parent->callscompleted + qe->parent->callsabandoned) == 0) {
4514 qe->parent->holdtime = newholdtime;
4515 } else {
4516 oldvalue = qe->parent->holdtime;
4517 qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newholdtime) >> 2;
4518 }
4519 ao2_unlock(qe->parent);
4520}
4521
4522/*! \brief Caller leaving queue.
4523 *
4524 * Search the queue to find the leaving client, if found remove from queue
4525 * create manager event, move others up the queue.
4526*/
4527static void leave_queue(struct queue_ent *qe)
4528{
4529 struct call_queue *q;
4530 struct queue_ent *current, *prev = NULL;
4531 struct penalty_rule *pr_iter;
4532 int pos = 0;
4533
4534 if (!(q = qe->parent)) {
4535 return;
4536 }
4537 queue_t_ref(q, "Copy queue pointer from queue entry");
4538 ao2_lock(q);
4539
4540 prev = NULL;
4541 for (current = q->head; current; current = current->next) {
4542 if (current == qe) {
4543 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
4544 char posstr[20];
4545 q->count--;
4546 if (!q->count) {
4548 }
4549
4550 blob = ast_json_pack("{s: s, s: i, s: i}",
4551 "Queue", q->name,
4552 "Position", qe->pos,
4553 "Count", q->count);
4554 ast_channel_publish_cached_blob(qe->chan, queue_caller_leave_type(), blob);
4555 ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, ast_channel_name(qe->chan));
4556 /* Take us out of the queue */
4557 if (prev) {
4558 prev->next = current->next;
4559 } else {
4560 q->head = current->next;
4561 }
4562 /* Free penalty rules */
4563 while ((pr_iter = AST_LIST_REMOVE_HEAD(&qe->qe_rules, list))) {
4564 ast_free(pr_iter);
4565 }
4566 qe->pr = NULL;
4567 snprintf(posstr, sizeof(posstr), "%d", qe->pos);
4568 pbx_builtin_setvar_helper(qe->chan, "QUEUEPOSITION", posstr);
4569 } else {
4570 /* Renumber the people after us in the queue based on a new count */
4571 current->pos = ++pos;
4572 prev = current;
4573 }
4574 }
4575 ao2_unlock(q);
4576
4577 /*If the queue is a realtime queue, check to see if it's still defined in real time*/
4578 if (q->realtime) {
4579 struct ast_variable *var;
4580 if (!(var = ast_load_realtime("queues", "name", q->name, SENTINEL))) {
4581 q->dead = 1;
4582 } else {
4584 }
4585 }
4586
4587 if (q->dead) {
4588 /* It's dead and nobody is in it, so kill it */
4589 queues_t_unlink(queues, q, "Queue is now dead; remove it from the container");
4590 }
4591 /* unref the explicit ref earlier in the function */
4592 queue_t_unref(q, "Expire copied reference");
4593}
4594
4595/*!
4596 * \internal
4597 * \brief Destroy the given callattempt structure and free it.
4598 * \since 1.8
4599 *
4600 * \param doomed callattempt structure to destroy.
4601 */
4602static void callattempt_free(struct callattempt *doomed)
4603{
4604 if (doomed->member) {
4605 ao2_ref(doomed->member, -1);
4606 }
4608 ast_free(doomed->orig_chan_name);
4609 ast_free(doomed);
4610}
4611
4612static void publish_dial_end_event(struct ast_channel *in, struct callattempt *outgoing, struct ast_channel *exception, const char *status)
4613{
4614 struct callattempt *cur;
4615
4616 for (cur = outgoing; cur; cur = cur->q_next) {
4617 if (cur->chan && cur->chan != exception) {
4619 }
4620 }
4621}
4622
4623/*! \brief Hang up a list of outgoing calls */
4624static void hangupcalls(struct queue_ent *qe, struct callattempt *outgoing, struct ast_channel *exception, int cancel_answered_elsewhere)
4625{
4626 struct callattempt *oo;
4627
4628 while (outgoing) {
4629 /* If someone else answered the call we should indicate this in the CANCEL */
4630 /* Hangup any existing lines we have open */
4631 if (outgoing->chan && (outgoing->chan != exception)) {
4632 if (exception || cancel_answered_elsewhere) {
4634 }
4635 ast_channel_publish_dial(qe->chan, outgoing->chan, outgoing->interface, "CANCEL");
4636
4637 /* When dialing channels it is possible that they may not ever
4638 * leave the not in use state (Local channels in particular) by
4639 * the time we cancel them. If this occurs but we know they were
4640 * dialed we explicitly remove them from the pending members
4641 * container so that subsequent call attempts occur.
4642 */
4643 if (outgoing->member->status == AST_DEVICE_NOT_INUSE) {
4645 }
4646
4647 ast_hangup(outgoing->chan);
4648 }
4649 oo = outgoing;
4650 outgoing = outgoing->q_next;
4652 callattempt_free(oo);
4653 }
4654}
4655
4656/*!
4657 * \brief Get the number of members available to accept a call.
4658 *
4659 * \note The queue passed in should be locked prior to this function call
4660 *
4661 * \param[in] q The queue for which we are counting the number of available members
4662 * \return Return the number of available members in queue q
4663 */
4665{
4666 struct member *mem;
4667 int avl = 0;
4668 struct ao2_iterator mem_iter;
4669
4670 mem_iter = ao2_iterator_init(q->members, 0);
4671 while ((mem = ao2_iterator_next(&mem_iter))) {
4672
4673 avl += is_member_available(q, mem);
4674 ao2_ref(mem, -1);
4675
4676 /* If autofill is not enabled or if the queue's strategy is ringall, then
4677 * we really don't care about the number of available members so much as we
4678 * do that there is at least one available.
4679 *
4680 * In fact, we purposely will return from this function stating that only
4681 * one member is available if either of those conditions hold. That way,
4682 * functions which determine what action to take based on the number of available
4683 * members will operate properly. The reasoning is that even if multiple
4684 * members are available, only the head caller can actually be serviced.
4685 */
4686 if ((!q->autofill || q->strategy == QUEUE_STRATEGY_RINGALL) && avl) {
4687 break;
4688 }
4689 }
4690 ao2_iterator_destroy(&mem_iter);
4691
4692 return avl;
4693}
4694
4695/* traverse all defined queues which have calls waiting and contain this member
4696 return 0 if no other queue has precedence (higher weight) or 1 if found */
4697static int compare_weight(struct call_queue *rq, struct member *member)
4698{
4699 struct call_queue *q;
4700 struct member *mem;
4701 int found = 0;
4702 struct ao2_iterator queue_iter;
4703
4704 queue_iter = ao2_iterator_init(queues, 0);
4705 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
4706 if (q == rq) { /* don't check myself, could deadlock */
4707 queue_t_unref(q, "Done with iterator");
4708 continue;
4709 }
4710 ao2_lock(q);
4711 if (q->count && q->members) {
4712 if ((mem = ao2_find(q->members, member, OBJ_POINTER))) {
4713 ast_debug(1, "Found matching member %s in queue '%s'\n", mem->interface, q->name);
4714 if (q->weight > rq->weight && q->count >= num_available_members(q)) {
4715 ast_debug(1, "Queue '%s' (weight %d, calls %d) is preferred over '%s' (weight %d, calls %d)\n", q->name, q->weight, q->count, rq->name, rq->weight, rq->count);
4716 found = 1;
4717 }
4718 ao2_ref(mem, -1);
4719 }
4720 }
4721 ao2_unlock(q);
4722 queue_t_unref(q, "Done with iterator");
4723 if (found) {
4724 break;
4725 }
4726 }
4727 ao2_iterator_destroy(&queue_iter);
4728 return found;
4729}
4730
4731static int is_longest_waiting_caller(struct queue_ent *caller, struct member *member)
4732{
4733 struct call_queue *q;
4734 struct member *mem;
4735 int is_longest_waiting = 1;
4736 struct ao2_iterator queue_iter;
4737 struct queue_ent *ch;
4738
4740 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
4741 if (q == caller->parent) { /* don't check myself, could deadlock */
4742 queue_t_unref(q, "Done with iterator");
4743 continue;
4744 }
4745 ao2_lock(q);
4746 /*
4747 * If the other queue has equal weight, see if we should let that handle
4748 * their call first. If weights are not equal, compare_weights will step in.
4749 */
4750 if (q->weight == caller->parent->weight && q->count && q->members) {
4751 if ((mem = ao2_find(q->members, member, OBJ_POINTER))) {
4752 ast_debug(2, "Found matching member %s in queue '%s'\n", mem->interface, q->name);
4753
4754 /* Does this queue have a caller that's been waiting longer? */
4755 ch = q->head;
4756 while (ch) {
4757 /* If ch->pending, the other call (which may be waiting for a longer period of time),
4758 * is already ringing at another agent. Ignore such callers; otherwise, all agents
4759 * will be unused until the first caller is picked up.
4760 */
4761 if (ch->start < caller->start && !ch->pending) {
4762 ast_debug(1, "Queue %s has a call at position %i that's been waiting longer (%li vs %li)\n",
4763 q->name, ch->pos, ch->start, caller->start);
4765 break;
4766 }
4767 ch = ch->next;
4768 }
4769 }
4770 }
4771 ao2_unlock(q);
4772 queue_t_unref(q, "Done with iterator");
4773 if (!is_longest_waiting) {
4774 break;
4775 }
4776 }
4778 return is_longest_waiting;
4779}
4780
4781/*! \brief common hangup actions */
4782static void do_hang(struct callattempt *o)
4783{
4784 o->stillgoing = 0;
4785 ast_hangup(o->chan);
4786 pending_members_remove(o->member);
4787 o->chan = NULL;
4788}
4789
4790/*!
4791 * \internal
4792 * \brief Check if the member status is available.
4793 *
4794 * \param status Member status to check if available.
4795 *
4796 * \retval non-zero if the member status is available.
4797 */
4799{
4801}
4802
4803/*!
4804 * \internal
4805 * \brief Determine if can ring a queue entry.
4806 *
4807 * \param qe Queue entry to check.
4808 * \param call Member call attempt.
4809 *
4810 * \retval non-zero if an entry can be called.
4811 */
4812static int can_ring_entry(struct queue_ent *qe, struct callattempt *call)
4813{
4814 struct member *memberp = call->member;
4815 int wrapuptime;
4816
4817 if (memberp->paused) {
4818 ast_debug(1, "%s paused, can't receive call\n", call->interface);
4819 return 0;
4820 }
4821
4822 if (!memberp->ringinuse && !member_status_available(memberp->status)) {
4823 ast_debug(1, "%s not available, can't receive call\n", call->interface);
4824 return 0;
4825 }
4826
4827 if (memberp->lastqueue) {
4828 wrapuptime = get_wrapuptime(memberp->lastqueue, memberp);
4829 } else {
4830 wrapuptime = get_wrapuptime(qe->parent, memberp);
4831 }
4832 if (wrapuptime && (time(NULL) - memberp->lastcall) < wrapuptime) {
4833 ast_debug(1, "Wrapuptime not yet expired on queue %s for %s\n",
4834 (memberp->lastqueue ? memberp->lastqueue->name : qe->parent->name),
4835 call->interface);
4836 return 0;
4837 }
4838
4839 if (use_weight && compare_weight(qe->parent, memberp)) {
4840 ast_debug(1, "Priority queue delaying call to %s:%s\n",
4841 qe->parent->name, call->interface);
4842 return 0;
4843 }
4844
4846 ast_debug(1, "Another caller was waiting longer; delaying call to %s:%s\n",
4847 qe->parent->name, call->interface);
4848 return 0;
4849 }
4850
4851 if (!memberp->ringinuse) {
4852 struct member *mem;
4853
4855
4856 mem = ao2_find(pending_members, memberp,
4858 if (mem) {
4859 /*
4860 * If found that means this member is currently being attempted
4861 * from another calling thread, so stop trying from this thread
4862 */
4863 ast_debug(1, "%s has another call trying, can't receive call\n",
4864 call->interface);
4865 ao2_ref(mem, -1);
4867 return 0;
4868 }
4869
4870 /*
4871 * If not found add it to the container so another queue
4872 * won't attempt to call this member at the same time.
4873 */
4874 ast_debug(3, "Add %s to pending_members\n", memberp->membername);
4875 ao2_link(pending_members, memberp);
4877
4878 /*
4879 * The queue member is available. Get current status to be sure
4880 * because the device state and extension state callbacks may
4881 * not have updated the status yet.
4882 */
4884 ast_debug(1, "%s actually not available, can't receive call\n",
4885 call->interface);
4886 pending_members_remove(memberp);
4887 return 0;
4888 }
4889 }
4890
4891 return 1;
4892}
4893
4894/*!
4895 * \brief Part 2 of ring_one
4896 *
4897 * Does error checking before attempting to request a channel and call a member.
4898 * This function is only called from ring_one().
4899 * Failure can occur if:
4900 * - Agent on call
4901 * - Agent is paused
4902 * - Wrapup time not expired
4903 * - Priority by another queue
4904 *
4905 * \retval 1 on success to reach a free agent
4906 * \retval 0 on failure to get agent.
4907 */
4908static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies)
4909{
4910 int res;
4911 int status;
4912 char tech[256];
4913 char *location;
4914 struct ast_format_cap *nativeformats;
4915 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
4916
4917 /* on entry here, we know that tmp->chan == NULL */
4918 if (!can_ring_entry(qe, tmp)) {
4919 tmp->stillgoing = 0;
4920 ++*busies;
4921 return 0;
4922 }
4923
4924 ast_copy_string(tech, tmp->interface, sizeof(tech));
4925 if ((location = strchr(tech, '/'))) {
4926 *location++ = '\0';
4927 } else {
4928 location = "";
4929 }
4930
4932 nativeformats = ao2_bump(ast_channel_nativeformats(qe->chan));
4934
4935 /* Request the peer */
4936 tmp->chan = ast_request(tech, nativeformats, NULL, qe->chan, location, &status);
4937 ao2_cleanup(nativeformats);
4938 if (!tmp->chan) { /* If we can't, just go on to the next call */
4939 ao2_lock(qe->parent);
4940 qe->parent->rrpos++;
4941 qe->linpos++;
4942 ao2_unlock(qe->parent);
4943
4945
4946 publish_dial_end_event(qe->chan, tmp, NULL, "BUSY");
4947 tmp->stillgoing = 0;
4948 ++*busies;
4949 return 0;
4950 }
4951
4952 ast_channel_lock_both(tmp->chan, qe->chan);
4953
4956 if (qe->cancel_answered_elsewhere) {
4958 }
4959 ast_channel_appl_set(tmp->chan, "AppQueue");
4960 ast_channel_data_set(tmp->chan, "(Outgoing Line)");
4961 memset(ast_channel_whentohangup(tmp->chan), 0, sizeof(*ast_channel_whentohangup(tmp->chan)));
4962
4963 /* If the new channel has no callerid, try to guess what it should be */
4964 if (!ast_channel_caller(tmp->chan)->id.number.valid) {
4966 struct ast_party_caller caller;
4967
4969 caller.id = ast_channel_connected(qe->chan)->id;
4970 caller.ani = ast_channel_connected(qe->chan)->ani;
4971 ast_channel_set_caller_event(tmp->chan, &caller, NULL);
4972 } else if (!ast_strlen_zero(ast_channel_dialed(qe->chan)->number.str)) {
4974 } else if (!ast_strlen_zero(ast_channel_exten(qe->chan))) {
4976 }
4977 tmp->dial_callerid_absent = 1;
4978 }
4979
4981
4983
4985
4986 /* Inherit specially named variables from parent channel */
4990
4991 /* Presense of ADSI CPE on outgoing channel follows ours */
4993
4994 /* Inherit context and extension */
4995 ast_channel_dialcontext_set(tmp->chan, ast_channel_context(qe->chan));
4997
4998 /* Save the original channel name to detect call pickup masquerading in. */
5000
5003
5004 /* location is tmp->interface where tech/ has been stripped, so it follow the same syntax as DIALEDPEERNUMBER in app_dial.c */
5005 pbx_builtin_setvar_helper(tmp->chan, "DIALEDPEERNUMBER", strlen(location) ? location : tmp->interface);
5006
5007 /* PREDIAL: Run gosub on the callee's channel */
5008 if (qe->predial_callee) {
5009 ast_pre_call(tmp->chan, qe->predial_callee);
5010 }
5011
5012 /* Place the call, but don't wait on the answer */
5013 if ((res = ast_call(tmp->chan, location, 0))) {
5014 /* Again, keep going even if there's an error */
5015 ast_verb(3, "Couldn't call %s\n", tmp->interface);
5016 do_hang(tmp);
5017 ++*busies;
5018 return 0;
5019 }
5020
5021 ast_channel_lock_both(tmp->chan, qe->chan);
5022
5023 blob = ast_json_pack("{s: s, s: s, s: s}",
5024 "Queue", qe->parent->name,
5025 "Interface", tmp->interface,
5026 "MemberName", tmp->member->membername);
5027 queue_publish_multi_channel_blob(qe->chan, tmp->chan, queue_agent_called_type(), blob);
5028
5030
5033
5034 ast_verb(3, "Called %s\n", tmp->interface);
5035
5036 return 1;
5037}
5038
5039/*! \brief find the entry with the best metric, or NULL */
5041{
5042 struct callattempt *best = NULL, *cur;
5043
5044 for (cur = outgoing; cur; cur = cur->q_next) {
5045 if (cur->stillgoing && /* Not already done */
5046 !cur->chan && /* Isn't already going */
5047 (!best || cur->metric < best->metric)) { /* We haven't found one yet, or it's better */
5048 best = cur;
5049 }
5050 }
5051
5052 return best;
5053}
5054
5055/*!
5056 * \brief Place a call to a queue member.
5057 *
5058 * Once metrics have been calculated for each member, this function is used
5059 * to place a call to the appropriate member (or members). The low-level
5060 * channel-handling and error detection is handled in ring_entry
5061 *
5062 * \retval 1 if a member was called successfully
5063 * \retval 0 otherwise
5064 */
5065static int ring_one(struct queue_ent *qe, struct callattempt *outgoing, int *busies)
5066{
5067 int ret = 0;
5068 struct callattempt *cur;
5069
5070 if (qe->predial_callee) {
5072 for (cur = outgoing; cur; cur = cur->q_next) {
5073 if (cur->stillgoing && cur->chan) {
5075 }
5076 }
5077 }
5078
5079 while (ret == 0) {
5080 struct callattempt *best = find_best(outgoing);
5081 if (!best) {
5082 ast_debug(1, "Nobody left to try ringing in queue\n");
5083 break;
5084 }
5086 /* Ring everyone who shares this best metric (for ringall) */
5087 for (cur = outgoing; cur; cur = cur->q_next) {
5088 if (cur->stillgoing && !cur->chan && cur->metric <= best->metric) {
5089 ast_debug(1, "(Parallel) Trying '%s' with metric %d\n", cur->interface, cur->metric);
5090 ret |= ring_entry(qe, cur, busies);
5091 if (qe->predial_callee && cur->chan) {
5093 }
5094 }
5095 }
5096 } else {
5097 /* Ring just the best channel */
5098 ast_debug(1, "Trying '%s' with metric %d\n", best->interface, best->metric);
5099 ret = ring_entry(qe, best, busies);
5100 if (qe->predial_callee && best->chan) {
5102 }
5103 }
5104
5105 /* If we have timed out, break out */
5106 if (qe->expire && (time(NULL) >= qe->expire)) {
5107 ast_debug(1, "Queue timed out while ringing members.\n");
5108 ret = 0;
5109 break;
5110 }
5111 }
5112 if (qe->predial_callee) {
5113 for (cur = outgoing; cur; cur = cur->q_next) {
5114 if (cur->stillgoing && cur->chan) {
5116 }
5117 }
5119 }
5120
5121 return ret;
5122}
5123
5124/*! \brief Search for best metric and add to Round Robbin queue */
5125static int store_next_rr(struct queue_ent *qe, struct callattempt *outgoing)
5126{
5127 struct callattempt *best = find_best(outgoing);
5128
5129 if (best) {
5130 /* Ring just the best channel */
5131 ast_debug(1, "Next is '%s' with metric %d\n", best->interface, best->metric);
5132 qe->parent->rrpos = best->metric % 1000;
5133 } else {
5134 /* Just increment rrpos */
5135 if (qe->parent->wrapped) {
5136 /* No more channels, start over */
5137 qe->parent->rrpos = 0;
5138 } else {
5139 /* Prioritize next entry */
5140 qe->parent->rrpos++;
5141 }
5142 }
5143 qe->parent->wrapped = 0;
5144
5145 return 0;
5146}
5147
5148/*! \brief Search for best metric and add to Linear queue */
5149static int store_next_lin(struct queue_ent *qe, struct callattempt *outgoing)
5150{
5151 struct callattempt *best = find_best(outgoing);
5152
5153 if (best) {
5154 /* Ring just the best channel */
5155 ast_debug(1, "Next is '%s' with metric %d\n", best->interface, best->metric);
5156 qe->linpos = best->metric % 1000;
5157 } else {
5158 /* Just increment rrpos */
5159 if (qe->linwrapped) {
5160 /* No more channels, start over */
5161 qe->linpos = 0;
5162 } else {
5163 /* Prioritize next entry */
5164 qe->linpos++;
5165 }
5166 }
5167 qe->linwrapped = 0;
5168
5169 return 0;
5170}
5171
5172/*! \brief Playback announcement to queued members if period has elapsed */
5174{
5175 int res = 0;
5176 time_t now;
5177
5178 /* Get the current time */
5179 time(&now);
5180
5181 /* Check to see if it is time to announce */
5183 return 0;
5184 }
5185
5186 /* Stop the music on hold so we can play our own file */
5187 if (ringing) {
5188 ast_indicate(qe->chan,-1);
5189 } else {
5190 ast_moh_stop(qe->chan);
5191 }
5192
5193 ast_verb(3, "Playing periodic announcement\n");
5194
5196 qe->last_periodic_announce_sound = ((unsigned long) ast_random()) % qe->parent->numperiodicannounce;
5200 }
5201
5202 /* play the announcement */
5204
5205 if (res > 0 && !valid_exit(qe, res)) {
5206 res = 0;
5207 }
5208
5209 /* Resume Music on Hold if the caller is going to stay in the queue */
5210 if (!res) {
5211 if (ringing) {
5213 } else {
5214 ast_moh_start(qe->chan, qe->moh, NULL);
5215 }
5216 }
5217
5218 /* update last_periodic_announce_time */
5220 time(&qe->last_periodic_announce_time);
5221 } else {
5223 }
5224
5225 /* Update the current periodic announcement to the next announcement */
5226 if (!qe->parent->randomperiodicannounce) {
5228 }
5229
5230 return res;
5231}
5232
5233/*! \brief Record that a caller gave up on waiting in queue */
5234static void record_abandoned(struct queue_ent *qe)
5235{
5236 int callabandonedinsl = 0;
5237 time_t now;
5238
5239 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
5240
5241 pbx_builtin_setvar_helper(qe->chan, "ABANDONED", "TRUE");
5242
5244 ao2_lock(qe->parent);
5245 blob = ast_json_pack("{s: s, s: i, s: i, s: i}",
5246 "Queue", qe->parent->name,
5247 "Position", qe->pos,
5248 "OriginalPosition", qe->opos,
5249 "HoldTime", (int)(time(NULL) - qe->start));
5250
5251
5252 time(&now);
5253 callabandonedinsl = ((now - qe->start) <= qe->parent->servicelevel);
5254 if (callabandonedinsl) {
5256 }
5257
5258 qe->parent->callsabandoned++;
5259 ao2_unlock(qe->parent);
5260
5261 ast_channel_publish_cached_blob(qe->chan, queue_caller_abandon_type(), blob);
5262}
5263
5264/*! \brief RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer. */
5265static void rna(int rnatime, struct queue_ent *qe, struct ast_channel *peer, char *interface, char *membername, int autopause)
5266{
5267 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
5268
5269 ast_verb(3, "Nobody picked up in %d ms\n", rnatime);
5270
5271 /* Stop ringing, and resume MOH if specified */
5272 if (qe->ring_when_ringing) {
5273 ast_indicate(qe->chan, -1);
5274 ast_moh_start(qe->chan, qe->moh, NULL);
5275 }
5276
5277 blob = ast_json_pack("{s: s, s: s, s: s, s: i}",
5278 "Queue", qe->parent->name,
5279 "Interface", interface,
5280 "MemberName", membername,
5281 "RingTime", rnatime);
5282 queue_publish_multi_channel_blob(qe->chan, peer, queue_agent_ringnoanswer_type(), blob);
5283
5284 ast_queue_log(qe->parent->name, ast_channel_uniqueid(qe->chan), membername, "RINGNOANSWER", "%d", rnatime);
5286 if (qe->parent->autopausedelay > 0) {
5287 struct member *mem;
5288 ao2_lock(qe->parent);
5289 if ((mem = interface_exists(qe->parent, interface))) {
5290 time_t idletime = time(&idletime)-mem->lastcall;
5291 if ((mem->lastcall != 0) && (qe->parent->autopausedelay > idletime)) {
5292 ao2_unlock(qe->parent);
5293 ao2_ref(mem, -1);
5294 return;
5295 }
5296 ao2_ref(mem, -1);
5297 }
5298 ao2_unlock(qe->parent);
5299 }
5300 if (qe->parent->autopause == QUEUE_AUTOPAUSE_ON) {
5301 if (!set_member_paused(qe->parent->name, interface, "Auto-Pause", 1)) {
5302 ast_verb(3, "Auto-Pausing Queue Member %s in queue %s since they failed to answer.\n",
5303 interface, qe->parent->name);
5304 } else {
5305 ast_verb(3, "Failed to pause Queue Member %s in queue %s!\n", interface, qe->parent->name);
5306 }
5307 } else {
5308 /* If queue autopause is mode all, just don't send any queue to stop.
5309 * the function will stop in all queues */
5310 if (!set_member_paused("", interface, "Auto-Pause", 1)) {
5311 ast_verb(3, "Auto-Pausing Queue Member %s in all queues since they failed to answer on queue %s.\n",
5312 interface, qe->parent->name);
5313 } else {
5314 ast_verb(3, "Failed to pause Queue Member %s in all queues!\n", interface);
5315 }
5316 }
5317 }
5318 return;
5319}
5320
5321/*!
5322 * \internal
5323 * \brief Update connected line on chan from peer.
5324 * \since 13.6.0
5325 *
5326 * \param chan Channel to get connected line updated.
5327 * \param peer Channel providing connected line information.
5328 * \param is_caller Non-zero if chan is the calling channel.
5329 */
5330static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
5331{
5332 struct ast_party_connected_line connected_caller;
5333
5334 ast_party_connected_line_init(&connected_caller);
5335
5336 ast_channel_lock(peer);
5338 ast_channel_unlock(peer);
5340 if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)) {
5341 ast_channel_update_connected_line(chan, &connected_caller, NULL);
5342 }
5343 ast_party_connected_line_free(&connected_caller);
5344}
5345
5346#define AST_MAX_WATCHERS 256
5347/*!
5348 * \brief Wait for a member to answer the call
5349 *
5350 * \param[in] qe the queue_ent corresponding to the caller in the queue
5351 * \param[in] outgoing the list of callattempts. Relevant ones will have their chan and stillgoing parameters non-zero
5352 * \param[in] to the amount of time (in milliseconds) to wait for a response
5353 * \param[out] digit if a user presses a digit to exit the queue, this is the digit the caller pressed
5354 * \param[in] prebusies number of busy members calculated prior to calling wait_for_answer
5355 * \param[in] caller_disconnect if the 'H' option is used when calling Queue(), this is used to detect if the caller pressed * to disconnect the call
5356 * \param[in] forwardsallowed used to detect if we should allow call forwarding, based on the 'i' option to Queue()
5357 *
5358 * \todo eventually all call forward logic should be integrated into and replaced by ast_call_forward()
5359 */
5360static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed)
5361{
5362 const char *queue = qe->parent->name;
5363 struct callattempt *o, *start = NULL, *prev = NULL;
5364 int status;
5365 int numbusies = prebusies;
5366 int numnochan = 0;
5367 int stillgoing = 0;
5368 int orig = *to;
5369 struct ast_frame *f;
5370 struct callattempt *peer = NULL;
5371 struct ast_channel *winner;
5372 struct ast_channel *in = qe->chan;
5373 char on[80] = "";
5374 char membername[80] = "";
5375 long starttime = 0;
5376 long endtime = 0;
5377 char *inchan_name;
5378 struct timeval start_time_tv = ast_tvnow();
5379 int canceled_by_caller = 0; /* 1 when caller hangs up or press digit or press * */
5380
5382 inchan_name = ast_strdupa(ast_channel_name(qe->chan));
5384
5385 starttime = (long) time(NULL);
5386
5387 while ((*to = ast_remaining_ms(start_time_tv, orig)) && !peer) {
5388 int numlines, retry, pos = 1;
5389 struct ast_channel *watchers[AST_MAX_WATCHERS];
5390 watchers[0] = in;
5391 start = NULL;
5392
5393 for (retry = 0; retry < 2; retry++) {
5394 numlines = 0;
5395 for (o = outgoing; o; o = o->q_next) { /* Keep track of important channels */
5396 if (o->stillgoing) { /* Keep track of important channels */
5397 stillgoing = 1;
5398 if (o->chan) {
5399 if (pos < AST_MAX_WATCHERS) {
5400 watchers[pos++] = o->chan;
5401 }
5402 if (!start) {
5403 start = o;
5404 } else {
5405 prev->call_next = o;
5406 }
5407 prev = o;
5408 }
5409 } else if (prev) {
5410 prev->call_next = NULL;
5411 }
5412 numlines++;
5413 }
5414 if (pos > 1 /* found */ || !stillgoing /* nobody listening */ ||
5415 (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) /* ring would not be delivered */) {
5416 break;
5417 }
5418 /* On "ringall" strategy we only move to the next penalty level
5419 when *all* ringing phones are done in the current penalty level */
5420 ring_one(qe, outgoing, &numbusies);
5421 /* and retry... */
5422 }
5423 if (pos == 1 /* not found */) {
5424 if (numlines == (numbusies + numnochan)) {
5425 ast_debug(1, "Everyone is busy at this time\n");
5426 } else {
5427 ast_debug(3, "No one is answering queue '%s' (%d numlines / %d busies / %d failed channels)\n", queue, numlines, numbusies, numnochan);
5428 }
5429 *to = 0;
5430 return NULL;
5431 }
5432
5433 /* Poll for events from both the incoming channel as well as any outgoing channels */
5434 winner = ast_waitfor_n(watchers, pos, to);
5435
5436 /* Service all of the outgoing channels */
5437 for (o = start; o; o = o->call_next) {
5438 /* We go with a fixed buffer here instead of using ast_strdupa. Using
5439 * ast_strdupa in a loop like this one can cause a stack overflow
5440 */
5441 char ochan_name[AST_CHANNEL_NAME];
5442
5443 if (o->chan) {
5445 ast_copy_string(ochan_name, ast_channel_name(o->chan), sizeof(ochan_name));
5447 }
5448 if (o->stillgoing && (o->chan) && (ast_channel_state(o->chan) == AST_STATE_UP)) {
5449 if (!peer) {
5450 ast_verb(3, "%s answered %s\n", ochan_name, inchan_name);
5451 if (o->orig_chan_name
5452 && strcmp(o->orig_chan_name, ochan_name)) {
5453 /*
5454 * The channel name changed so we must generate COLP update.
5455 * Likely because a call pickup channel masqueraded in.
5456 */
5458 } else if (!o->block_connected_update) {
5459 if (o->pending_connected_update) {
5462 }
5463 } else if (!o->dial_callerid_absent) {
5465 }
5466 }
5467 if (o->aoc_s_rate_list) {
5468 size_t encoded_size;
5469 struct ast_aoc_encoded *encoded;
5470 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
5471 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
5472 ast_aoc_destroy_encoded(encoded);
5473 }
5474 }
5475 peer = o;
5476 }
5477 } else if (o->chan && (o->chan == winner)) {
5478
5479 ast_copy_string(on, o->member->interface, sizeof(on));
5480 ast_copy_string(membername, o->member->membername, sizeof(membername));
5481
5482 /* Before processing channel, go ahead and check for forwarding */
5483 if (!ast_strlen_zero(ast_channel_call_forward(o->chan)) && !forwardsallowed) {
5484 ast_verb(3, "Forwarding %s to '%s' prevented.\n", inchan_name, ast_channel_call_forward(o->chan));
5486 "CANCEL", ast_channel_call_forward(o->chan));
5487 numnochan++;
5488 do_hang(o);
5489 winner = NULL;
5490 continue;
5492 struct ast_channel *original = o->chan;
5493 char forwarder[AST_CHANNEL_NAME];
5494 char tmpchan[256];
5495 char *stuff;
5496 char *tech;
5497 int failed = 0;
5498
5499 ast_copy_string(tmpchan, ast_channel_call_forward(o->chan), sizeof(tmpchan));
5500 ast_copy_string(forwarder, ast_channel_name(o->chan), sizeof(forwarder));
5501 if ((stuff = strchr(tmpchan, '/'))) {
5502 *stuff++ = '\0';
5503 tech = tmpchan;
5504 } else {
5505 const char *forward_context;
5507 forward_context = pbx_builtin_getvar_helper(o->chan, "FORWARD_CONTEXT");
5508 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(o->chan), forward_context ? forward_context : ast_channel_context(o->chan));
5510 stuff = tmpchan;
5511 tech = "Local";
5512 }
5513 if (!strcasecmp(tech, "Local")) {
5514 /*
5515 * Drop the connected line update block for local channels since
5516 * this is going to run dialplan and the user can change his
5517 * mind about what connected line information he wants to send.
5518 */
5520 }
5521
5522 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", inchan_name, tech, stuff, ochan_name);
5523 /* Setup parameters */
5525 if (!o->chan) {
5527 "Forwarding failed to create channel to dial '%s/%s'\n",
5528 tech, stuff);
5529 o->stillgoing = 0;
5530 numnochan++;
5531 } else {
5532 ast_channel_lock_both(o->chan, original);
5534 ast_channel_redirecting(original));
5536 ast_channel_unlock(original);
5537
5541 pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
5543
5544 if (o->pending_connected_update) {
5545 /*
5546 * Re-seed the callattempt's connected line information with
5547 * previously acquired connected line info from the queued
5548 * channel. The previously acquired connected line info could
5549 * have been set through the CONNECTED_LINE dialplan function.
5550 */
5553 }
5554
5557
5559
5562 /*
5563 * The call was not previously redirected so it is
5564 * now redirected from this number.
5565 */
5571 }
5572
5574
5579
5582 && !o->block_connected_update) {
5583 struct ast_party_redirecting redirecting;
5584
5585 /*
5586 * Redirecting updates to the caller make sense only on single
5587 * call at a time strategies.
5588 *
5589 * Need to re-evaluate if calling unlock is still required as we no longer
5590 * use macro.
5591 */
5592 ast_party_redirecting_init(&redirecting);
5595 if (ast_channel_redirecting_sub(o->chan, in, &redirecting, 0)) {
5596 ast_channel_update_redirecting(in, &redirecting, NULL);
5597 }
5598 ast_party_redirecting_free(&redirecting);
5599 } else {
5601 }
5602
5603 if (ast_call(o->chan, stuff, 0)) {
5604 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
5605 tech, stuff);
5606 failed = 1;
5607 }
5608 }
5609
5611 "CANCEL", ast_channel_call_forward(original));
5612 if (o->chan) {
5613 ast_channel_publish_dial(qe->chan, o->chan, stuff, NULL);
5614 }
5615
5616 if (failed) {
5617 do_hang(o);
5618 numnochan++;
5619 }
5620
5621 /* Hangup the original channel now, in case we needed it */
5622 ast_hangup(winner);
5623 continue;
5624 }
5625 f = ast_read(winner);
5626 if (f) {
5627 if (f->frametype == AST_FRAME_CONTROL) {
5628 switch (f->subclass.integer) {
5629 case AST_CONTROL_ANSWER:
5630 /* This is our guy if someone answered. */
5631 if (!peer) {
5632 ast_verb(3, "%s answered %s\n", ochan_name, inchan_name);
5633 ast_channel_publish_dial(qe->chan, o->chan, on, "ANSWER");
5634 publish_dial_end_event(qe->chan, outgoing, o->chan, "CANCEL");
5635 if (o->orig_chan_name
5636 && strcmp(o->orig_chan_name, ochan_name)) {
5637 /*
5638 * The channel name changed so we must generate COLP update.
5639 * Likely because a call pickup channel masqueraded in.
5640 */
5642 } else if (!o->block_connected_update) {
5643 if (o->pending_connected_update) {
5646 }
5647 } else if (!o->dial_callerid_absent) {
5649 }
5650 }
5651 if (o->aoc_s_rate_list) {
5652 size_t encoded_size;
5653 struct ast_aoc_encoded *encoded;
5654 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
5655 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
5656 ast_aoc_destroy_encoded(encoded);
5657 }
5658 }
5659 peer = o;
5660 }
5661 break;
5662 case AST_CONTROL_BUSY:
5663 ast_verb(3, "%s is busy\n", ochan_name);
5664 ast_channel_publish_dial(qe->chan, o->chan, on, "BUSY");
5665 endtime = (long) time(NULL);
5666 endtime -= starttime;
5667 rna(endtime * 1000, qe, o->chan, on, membername, qe->parent->autopausebusy);
5668 do_hang(o);
5670 if (qe->parent->timeoutrestart) {
5671 start_time_tv = ast_tvnow();
5672 }
5673 /* Have enough time for a queue member to answer? */
5674 if (ast_remaining_ms(start_time_tv, orig) > 500) {
5675 ring_one(qe, outgoing, &numbusies);
5676 starttime = (long) time(NULL);
5677 }
5678 }
5679 numbusies++;
5680 break;
5682 ast_verb(3, "%s is circuit-busy\n", ochan_name);
5683 ast_channel_publish_dial(qe->chan, o->chan, on, "CONGESTION");
5684 endtime = (long) time(NULL);
5685 endtime -= starttime;
5686 rna(endtime * 1000, qe, o->chan, on, membername, qe->parent->autopauseunavail);
5687 do_hang(o);
5689 if (qe->parent->timeoutrestart) {
5690 start_time_tv = ast_tvnow();
5691 }
5692 if (ast_remaining_ms(start_time_tv, orig) > 500) {
5693 ring_one(qe, outgoing, &numbusies);
5694 starttime = (long) time(NULL);
5695 }
5696 }
5697 numbusies++;
5698 break;
5700 ast_verb(3, "%s is ringing\n", ochan_name);
5701
5702 ast_channel_publish_dial(qe->chan, o->chan, on, "RINGING");
5703
5704 /* Start ring indication when the channel is ringing, if specified */
5705 if (qe->ring_when_ringing) {
5706 ast_moh_stop(qe->chan);
5708 }
5709 break;
5711 /* Ignore going off hook */
5712 break;
5714 if (o->block_connected_update) {
5715 ast_verb(3, "Connected line update to %s prevented.\n", inchan_name);
5716 break;
5717 }
5720
5721 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", ochan_name, inchan_name);
5727 break;
5728 }
5729
5730 /*
5731 * Prevent using the CallerID from the outgoing channel since we
5732 * got a connected line update from it.
5733 */
5734 o->dial_callerid_absent = 1;
5735
5736 if (ast_channel_connected_line_sub(o->chan, in, f, 1)) {
5738 }
5739 break;
5740 case AST_CONTROL_AOC:
5741 {
5742 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
5743 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
5745 o->aoc_s_rate_list = decoded;
5746 } else {
5747 ast_aoc_destroy_decoded(decoded);
5748 }
5749 }
5750 break;
5753 /*
5754 * Redirecting updates to the caller make sense only on single
5755 * call at a time strategies.
5756 */
5757 break;
5758 }
5759 if (o->block_connected_update) {
5760 ast_verb(3, "Redirecting update to %s prevented\n",
5761 inchan_name);
5762 break;
5763 }
5764 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
5765 ochan_name, inchan_name);
5766 if (ast_channel_redirecting_sub(o->chan, in, f, 1)) {
5768 }
5769 break;
5772 break;
5773 default:
5774 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
5775 break;
5776 }
5777 }
5778 ast_frfree(f);
5779 } else { /* ast_read() returned NULL */
5780 endtime = (long) time(NULL) - starttime;
5781 ast_channel_publish_dial(qe->chan, o->chan, on, "NOANSWER");
5782 rna(endtime * 1000, qe, o->chan, on, membername, 1);
5783 do_hang(o);
5785 if (qe->parent->timeoutrestart) {
5786 start_time_tv = ast_tvnow();
5787 }
5788 if (ast_remaining_ms(start_time_tv, orig) > 500) {
5789 ring_one(qe, outgoing, &numbusies);
5790 starttime = (long) time(NULL);
5791 }
5792 }
5793 }
5794 }
5795 }
5796
5797 /* If we received an event from the caller, deal with it. */
5798 if (winner == in) {
5799 f = ast_read(in);
5800 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
5801 /* Got hung up */
5802 *to = -1;
5803 if (f) {
5804 if (f->data.uint32) {
5806 }
5807 ast_frfree(f);
5808 }
5809 canceled_by_caller = 1;
5810 } else if ((f->frametype == AST_FRAME_DTMF) && caller_disconnect && (f->subclass.integer == '*')) {
5811 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
5812 *to = 0;
5813 ast_frfree(f);
5814 canceled_by_caller = 1;
5815 } else if ((f->frametype == AST_FRAME_DTMF) && valid_exit(qe, f->subclass.integer)) {
5816 ast_verb(3, "User pressed digit: %c\n", f->subclass.integer);
5817 *to = 0;
5818 *digit = f->subclass.integer;
5819 ast_frfree(f);
5820 canceled_by_caller = 1;
5821 }
5822 /* When caller hung up or pressed * or digit. */
5823 if (canceled_by_caller) {
5825 for (o = start; o; o = o->call_next) {
5826 if (o->chan) {
5827 ast_queue_log(qe->parent->name, ast_channel_uniqueid(qe->chan), o->member->membername, "RINGCANCELED", "%d", (int) ast_tvdiff_ms(ast_tvnow(), start_time_tv));
5828 }
5829 }
5830 return NULL;
5831 }
5832
5833 /* Send the frame from the in channel to all outgoing channels. */
5834 for (o = start; o; o = o->call_next) {
5835 if (!o->stillgoing || !o->chan) {
5836 /* This outgoing channel has died so don't send the frame to it. */
5837 continue;
5838 }
5839 switch (f->frametype) {
5840 case AST_FRAME_CONTROL:
5841 switch (f->subclass.integer) {
5843 if (o->block_connected_update) {
5844 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
5845 break;
5846 }
5847 if (ast_channel_connected_line_sub(in, o->chan, f, 1)) {
5849 }
5850 break;
5852 if (o->block_connected_update) {
5853 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
5854 break;
5855 }
5856 if (ast_channel_redirecting_sub(in, o->chan, f, 1)) {
5858 }
5859 break;
5860 default:
5861 /* We are not going to do anything with this frame. */
5862 goto skip_frame;
5863 }
5864 break;
5865 default:
5866 /* We are not going to do anything with this frame. */
5867 goto skip_frame;
5868 }
5869 }
5870skip_frame:;
5871
5872 ast_frfree(f);
5873 }
5874 }
5875
5876 if (!*to) {
5877 for (o = start; o; o = o->call_next) {
5878 if (o->chan) {
5879 rna(orig, qe, o->chan, o->interface, o->member->membername, 1);
5880 }
5881 }
5882
5883 publish_dial_end_event(qe->chan, outgoing, NULL, "NOANSWER");
5884 }
5885
5886 return peer;
5887}
5888
5889/*!
5890 * \brief Check if we should start attempting to call queue members.
5891 *
5892 * A simple process, really. Count the number of members who are available
5893 * to take our call and then see if we are in a position in the queue at
5894 * which a member could accept our call.
5895 *
5896 * \param[in] qe The caller who wants to know if it is his turn
5897 * \retval 0 It is not our turn
5898 * \retval 1 It is our turn
5899 */
5900static int is_our_turn(struct queue_ent *qe)
5901{
5902 struct queue_ent *ch;
5903 int res;
5904 int avl;
5905 int idx = 0;
5906 /* This needs a lock. How many members are available to be served? */
5907 ao2_lock(qe->parent);
5908
5909 avl = num_available_members(qe->parent);
5910
5911 ch = qe->parent->head;
5912
5913 ast_debug(1, "There %s %d available %s.\n", avl != 1 ? "are" : "is", avl, avl != 1 ? "members" : "member");
5914
5915 while ((idx < avl) && (ch) && (ch != qe)) {
5916 if (!ch->pending) {
5917 idx++;
5918 }
5919 ch = ch->next;
5920 }
5921
5922 ao2_unlock(qe->parent);
5923 /* If the queue entry is within avl [the number of available members] calls from the top ...
5924 * Autofill and position check added to support autofill=no (as only calls
5925 * from the front of the queue are valid when autofill is disabled)
5926 */
5927 if (ch && idx < avl && (qe->parent->autofill || qe->pos == 1)) {
5928 ast_debug(1, "It's our turn (%s).\n", ast_channel_name(qe->chan));
5929 res = 1;
5930 } else {
5931 ast_debug(1, "It's not our turn (%s).\n", ast_channel_name(qe->chan));
5932 res = 0;
5933 }
5934
5935 /* Update realtime members if this is the first call and number of avalable members is 0 */
5936 if (avl == 0 && qe->pos == 1) {
5937 update_realtime_members(qe->parent);
5938 }
5939
5940 return res;
5941}
5942
5943/*!
5944 * \brief update rules for queues
5945 *
5946 * Calculate min/max penalties making sure if relative they stay within bounds.
5947 * Update queues penalty and set dialplan vars, goto next list entry.
5948*/
5949static void update_qe_rule(struct queue_ent *qe)
5950{
5951 int max_penalty = INT_MAX;
5952
5953 if (qe->max_penalty != INT_MAX) {
5954 char max_penalty_str[20];
5955
5956 if (qe->pr->max_relative) {
5957 max_penalty = qe->max_penalty + qe->pr->max_value;
5958 } else {
5959 max_penalty = qe->pr->max_value;
5960 }
5961
5962 /* a relative change to the penalty could put it below 0 */
5963 if (max_penalty < 0) {
5964 max_penalty = 0;
5965 }
5966
5968 pbx_builtin_setvar_helper(qe->chan, "QUEUE_MAX_PENALTY", max_penalty_str);
5969 qe->max_penalty = max_penalty;
5970 ast_debug(3, "Setting max penalty to %d for caller %s since %d seconds have elapsed\n",
5971 qe->max_penalty, ast_channel_name(qe->chan), qe->pr->time);
5972 }
5973
5974 if (qe->min_penalty != INT_MAX) {
5975 char min_penalty_str[20];
5976 int min_penalty;
5977
5978 if (qe->pr->min_relative) {
5979 min_penalty = qe->min_penalty + qe->pr->min_value;
5980 } else {
5981 min_penalty = qe->pr->min_value;
5982 }
5983
5984 /* a relative change to the penalty could put it below 0 */
5985 if (min_penalty < 0) {
5986 min_penalty = 0;
5987 }
5988
5991 }
5992
5994 pbx_builtin_setvar_helper(qe->chan, "QUEUE_MIN_PENALTY", min_penalty_str);
5995 qe->min_penalty = min_penalty;
5996 ast_debug(3, "Setting min penalty to %d for caller %s since %d seconds have elapsed\n",
5997 qe->min_penalty, ast_channel_name(qe->chan), qe->pr->time);
5998 }
5999
6000 if (qe->raise_penalty != INT_MAX) {
6001 char raise_penalty_str[20];
6002 int raise_penalty;
6003
6004 if (qe->pr->raise_relative) {
6005 raise_penalty = qe->raise_penalty + qe->pr->raise_value;
6006 } else {
6007 raise_penalty = qe->pr->raise_value;
6008 }
6009
6010 /* a relative change to the penalty could put it below 0 */
6011 if (raise_penalty < 0) {
6012 raise_penalty = 0;
6013 }
6014
6017 }
6018
6020 pbx_builtin_setvar_helper(qe->chan, "QUEUE_RAISE_PENALTY", raise_penalty_str);
6021 qe->raise_penalty = raise_penalty;
6022 ast_debug(3, "Setting raised penalty to %d for caller %s since %d seconds have elapsed\n",
6023 qe->raise_penalty, ast_channel_name(qe->chan), qe->pr->time);
6024 }
6025
6026 qe->pr = AST_LIST_NEXT(qe->pr, list);
6027}
6028
6029/*! \brief The waiting areas for callers who are not actively calling members
6030 *
6031 * This function is one large loop. This function will return if a caller
6032 * either exits the queue or it becomes that caller's turn to attempt calling
6033 * queue members. Inside the loop, we service the caller with periodic announcements,
6034 * holdtime announcements, etc. as configured in queues.conf
6035 *
6036 * \retval 0 if the caller's turn has arrived
6037 * \retval -1 if the caller should exit the queue.
6038 */
6039static int wait_our_turn(struct queue_ent *qe, int ringing, enum queue_result *reason)
6040{
6041 int res = 0;
6042
6043 /* This is the holding pen for callers 2 through maxlen */
6044 for (;;) {
6045
6046 /* A request to withdraw this call from the queue arrived */
6047 if (qe->withdraw) {
6048 *reason = QUEUE_WITHDRAW;
6049 res = 1;
6050 break;
6051 }
6052
6053 if (is_our_turn(qe)) {
6054 break;
6055 }
6056
6057 /* If we have timed out, break out */
6058 if (qe->expire && (time(NULL) >= qe->expire)) {
6059 *reason = QUEUE_TIMEOUT;
6060 break;
6061 }
6062
6063 if (qe->parent->leavewhenempty) {
6064 int status = 0;
6065
6066 if ((status = get_member_status(qe->parent, qe->max_penalty, qe->min_penalty, qe->raise_penalty, qe->parent->leavewhenempty, 0, qe->raise_respect_min))) {
6068 *reason = QUEUE_LEAVEEMPTY;
6069 ast_queue_log(qe->parent->name, ast_channel_uniqueid(qe->chan), "NONE", "EXITEMPTY", "%d|%d|%ld", qe->pos, qe->opos, (long) (time(NULL) - qe->start));
6070 res = -1;
6071 qe->handled = -1;
6072 break;
6073 }
6074 }
6075
6076 /* Make a position announcement, if enabled */
6077 if (qe->parent->announcefrequency &&
6078 (res = say_position(qe,ringing))) {
6079 break;
6080 }
6081
6082 /* If we have timed out, break out */
6083 if (qe->expire && (time(NULL) >= qe->expire)) {
6084 *reason = QUEUE_TIMEOUT;
6085 break;
6086 }
6087
6088 /* Make a periodic announcement, if enabled */
6089 if (qe->parent->periodicannouncefrequency &&
6091 break;
6092
6093 /* see if we need to move to the next penalty level for this queue */
6094 while (qe->pr && ((time(NULL) - qe->start) >= qe->pr->time)) {
6096 }
6097
6098 /* If we have timed out, break out */
6099 if (qe->expire && (time(NULL) >= qe->expire)) {
6100 *reason = QUEUE_TIMEOUT;
6101 break;
6102 }
6103
6104 /* Wait a second before checking again */
6105 if ((res = ast_waitfordigit(qe->chan, RECHECK * 1000))) {
6106 if (res > 0 && !valid_exit(qe, res)) {
6107 res = 0;
6108 } else {
6109 break;
6110 }
6111 }
6112
6113 /* If we have timed out, break out */
6114 if (qe->expire && (time(NULL) >= qe->expire)) {
6115 *reason = QUEUE_TIMEOUT;
6116 break;
6117 }
6118 }
6119
6120 return res;
6121}
6122
6123/*!
6124 * \brief update the queue status
6125 * \retval 0 always
6126*/
6127static int update_queue(struct call_queue *q, struct member *member, int callcompletedinsl, time_t starttime)
6128{
6129 int oldtalktime;
6130 int newtalktime = time(NULL) - starttime;
6131 struct member *mem;
6132 struct call_queue *qtmp;
6133 struct ao2_iterator queue_iter;
6134
6135 /* It is possible for us to be called when a call has already been considered terminated
6136 * and data updated, so to ensure we only act on the call that the agent is currently in
6137 * we check when the call was bridged.
6138 */
6139 if (!starttime || (member->starttime != starttime)) {
6140 return 0;
6141 }
6142
6143 if (shared_lastcall) {
6144 queue_iter = ao2_iterator_init(queues, 0);
6145 while ((qtmp = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
6146 ao2_lock(qtmp);
6147 if ((mem = ao2_find(qtmp->members, member, OBJ_POINTER))) {
6148 time(&mem->lastcall);
6149 mem->calls++;
6150 mem->callcompletedinsl = 0;
6151 mem->starttime = 0;
6152 mem->lastqueue = q;
6153 ao2_ref(mem, -1);
6154 }
6155 ao2_unlock(qtmp);
6156 queue_t_unref(qtmp, "Done with iterator");
6157 }
6158 ao2_iterator_destroy(&queue_iter);
6159 } else {
6160 ao2_lock(q);
6161 time(&member->lastcall);
6163 member->calls++;
6164 member->starttime = 0;
6165 member->lastqueue = q;
6166 ao2_unlock(q);
6167 }
6168 /* Member might never experience any direct status change (local
6169 * channel with forwarding in particular). If that's the case,
6170 * this is the last chance to remove it from pending or subsequent
6171 * calls will not occur.
6172 */
6174
6175 ao2_lock(q);
6176 q->callscompleted++;
6177 if (callcompletedinsl) {
6178 q->callscompletedinsl++;
6179 }
6180 if (q->callscompleted == 1) {
6181 q->talktime = newtalktime;
6182 } else {
6183 /* Calculate talktime using the same exponential average as holdtime code */
6184 oldtalktime = q->talktime;
6185 q->talktime = (((oldtalktime << 2) - oldtalktime) + newtalktime) >> 2;
6186 }
6187 ao2_unlock(q);
6188 return 0;
6189}
6190
6191/*! \brief Calculate the metric of each member in the outgoing callattempts
6192 *
6193 * A numeric metric is given to each member depending on the ring strategy used
6194 * by the queue. Members with lower metrics will be called before members with
6195 * higher metrics
6196 * \retval -1 if penalties are exceeded
6197 * \retval 0 otherwise
6198 */
6199static int calc_metric(struct call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct callattempt *tmp)
6200{
6201 /* disregarding penalty on too few members? */
6202 int membercount = ao2_container_count(q->members);
6203 unsigned char usepenalty = (membercount <= q->penaltymemberslimit) ? 0 : 1;
6204 int penalty = mem->penalty;
6205
6206 if (usepenalty) {
6207 if (qe->raise_penalty != INT_MAX && penalty < qe->raise_penalty) {
6208 /* Low penalty is raised up to the current minimum */
6209 penalty = qe->raise_penalty;
6210 }
6211 if ((qe->max_penalty != INT_MAX && penalty > qe->max_penalty) ||
6212 (qe->min_penalty != INT_MAX && penalty < qe->min_penalty)) {
6213 return -1;
6214 }
6215 } else {
6216 ast_debug(1, "Disregarding penalty, %d members and %d in penaltymemberslimit.\n",
6217 membercount, q->penaltymemberslimit);
6218 }
6219
6220 switch (q->strategy) {
6222 /* Everyone equal, except for penalty */
6223 tmp->metric = penalty * 1000000 * usepenalty;
6224 break;
6226 if (pos < qe->linpos) {
6227 tmp->metric = 1000 + pos;
6228 } else {
6229 if (pos > qe->linpos) {
6230 /* Indicate there is another priority */
6231 qe->linwrapped = 1;
6232 }
6233 tmp->metric = pos;
6234 }
6235 tmp->metric += penalty * 1000000 * usepenalty;
6236 break;
6239 pos = mem->queuepos;
6240 if (pos < q->rrpos) {
6241 tmp->metric = 1000 + pos;
6242 } else {
6243 if (pos > q->rrpos) {
6244 /* Indicate there is another priority */
6245 q->wrapped = 1;
6246 }
6247 tmp->metric = pos;
6248 }
6249 tmp->metric += penalty * 1000000 * usepenalty;
6250 break;
6252 tmp->metric = ast_random() % 1000;
6253 tmp->metric += penalty * 1000000 * usepenalty;
6254 break;
6256 tmp->metric = ast_random() % ((1 + penalty) * 1000);
6257 break;
6259 tmp->metric = mem->calls;
6260 tmp->metric += penalty * 1000000 * usepenalty;
6261 break;
6263 if (!mem->lastcall) {
6264 tmp->metric = 0;
6265 } else {
6266 tmp->metric = 1000000 - (time(NULL) - mem->lastcall);
6267 }
6268 tmp->metric += penalty * 1000000 * usepenalty;
6269 break;
6270 default:
6271 ast_log(LOG_WARNING, "Can't calculate metric for unknown strategy %d\n", q->strategy);
6272 break;
6273 }
6274 return 0;
6275}
6276
6282
6283/*! \brief Send out AMI message with member call completion status information */
6284static void send_agent_complete(const char *queuename, struct ast_channel_snapshot *caller,
6285 struct ast_channel_snapshot *peer, const struct member *member, time_t holdstart,
6286 time_t callstart, enum agent_complete_reason rsn)
6287{
6288 const char *reason = NULL; /* silence dumb compilers */
6289 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
6290
6291 switch (rsn) {
6292 case CALLER:
6293 reason = "caller";
6294 break;
6295 case AGENT:
6296 reason = "agent";
6297 break;
6298 case TRANSFER:
6299 reason = "transfer";
6300 break;
6301 }
6302
6303 blob = ast_json_pack("{s: s, s: s, s: s, s: I, s: I, s: s}",
6304 "Queue", queuename,
6305 "Interface", member->interface,
6306 "MemberName", member->membername,
6307 "HoldTime", (ast_json_int_t)(callstart - holdstart),
6308 "TalkTime", (ast_json_int_t)(time(NULL) - callstart),
6309 "Reason", reason ?: "");
6310
6312 queue_agent_complete_type(), blob);
6313}
6314
6315static void queue_agent_cb(void *userdata, struct stasis_subscription *sub,
6316 struct stasis_message *msg)
6317{
6318 struct ast_channel_blob *agent_blob;
6319
6320 agent_blob = stasis_message_data(msg);
6321
6323 ast_queue_log("NONE", agent_blob->snapshot->base->uniqueid,
6324 ast_json_string_get(ast_json_object_get(agent_blob->blob, "agent")),
6325 "AGENTLOGIN", "%s", agent_blob->snapshot->base->name);
6327 ast_queue_log("NONE", agent_blob->snapshot->base->uniqueid,
6328 ast_json_string_get(ast_json_object_get(agent_blob->blob, "agent")),
6329 "AGENTLOGOFF", "%s|%ld", agent_blob->snapshot->base->name,
6330 (long) ast_json_integer_get(ast_json_object_get(agent_blob->blob, "logintime")));
6331 }
6332}
6333
6334/*!
6335 * \brief Structure representing relevant data during a local channel optimization
6336 *
6337 * The reason we care about local channel optimizations is that we want to be able
6338 * to accurately report when the caller and queue member have stopped talking to
6339 * each other. A local channel optimization can cause it to appear that the conversation
6340 * has stopped immediately after it has begun. By tracking that the relevant channels
6341 * to monitor have changed due to a local channel optimization, we can give accurate
6342 * reports.
6343 *
6344 * Local channel optimizations for queues are restricted from their normal operation.
6345 * Bridges created by queues can only be the destination of local channel optimizations,
6346 * not the source. In addition, move-swap local channel optimizations are the only
6347 * permitted types of local channel optimization.
6348 *
6349 * This data is populated when we are told that a local channel optimization begin
6350 * is occurring. When we get told the optimization has ended successfully, we then
6351 * apply the data here into the queue_stasis_data.
6352 */
6354 /*! The uniqueid of the channel that will be taking the place of the caller or member */
6356 /*! Indication of whether we think there is a local channel optimization in progress */
6358 /*! The identifier for this local channel optimization */
6359 unsigned int id;
6360};
6361
6362/*!
6363 * \brief User data for stasis subscriptions used for queue calls.
6364 *
6365 * app_queue subscribes to channel and bridge events for all bridged calls.
6366 * app_queue cares about the following events:
6367 *
6368 * \li bridge enter: To determine the unique ID of the bridge created for the call.
6369 * \li blind transfer: To send an appropriate agent complete event.
6370 * \li attended transfer: To send an appropriate agent complete event.
6371 * \li local optimization: To update caller and member unique IDs for the call.
6372 * \li hangup: To send an appropriate agent complete event.
6373 *
6374 * The stasis subscriptions last until we determine that the caller and the member
6375 * are no longer bridged with each other.
6376 */
6379 /*! The unique ID of the caller's channel. */
6381 /*! The unique ID of the queue member's channel */
6383 /*! The unique ID of the bridge created by the queue */
6386 /*! The relevant queue */
6388 /*! The queue member that has answered the call */
6390 /*! The time at which the caller entered the queue. Start of the caller's hold time */
6392 /*! The time at which the member answered the call. */
6394 /*! The original position of the caller when he entered the queue */
6396 /*! Indication if the call was answered within the configured service level of the queue */
6398 /*! Indicates if the stasis subscriptions are shutting down */
6400 /*! The stasis message router for bridge events */
6402 /*! The stasis message router for channel events */
6404 /*! Local channel optimization details for the caller */
6406 /*! Local channel optimization details for the member */
6408};
6409
6410/*!
6411 * \internal
6412 * \brief Free memory for a queue_stasis_data
6413 */
6414static void queue_stasis_data_destructor(void *obj)
6415{
6416 struct queue_stasis_data *queue_data = obj;
6417
6418 /* This can only happen if refcounts for this object have got severely messed up */
6419 ast_assert(queue_data->bridge_router == NULL);
6420 ast_assert(queue_data->channel_router == NULL);
6421
6422 ao2_cleanup(queue_data->member);
6423 queue_unref(queue_data->queue);
6424 ast_string_field_free_memory(queue_data);
6425}
6426
6427/*!
6428 * \internal
6429 * \brief End all stasis subscriptions on a queue_stasis_data
6430 */
6431static void remove_stasis_subscriptions(struct queue_stasis_data *queue_data)
6432{
6433 SCOPED_AO2LOCK(lock, queue_data);
6434
6435 queue_data->dying = 1;
6437 queue_data->bridge_router = NULL;
6439 queue_data->channel_router = NULL;
6440}
6441
6442/*!
6443 * \internal
6444 * \brief Allocate a queue_stasis_data and initialize its data.
6445 */
6447 struct ast_channel *peer, struct member *mem, time_t holdstart,
6448 time_t starttime, int callcompletedinsl)
6449{
6450 struct queue_stasis_data *queue_data;
6451
6452 queue_data = ao2_alloc(sizeof(*queue_data), queue_stasis_data_destructor);
6453 if (!queue_data) {
6454 return NULL;
6455 }
6456
6457 if (ast_string_field_init(queue_data, 64)) {
6458 ao2_cleanup(queue_data);
6459 return NULL;
6460 }
6461
6464 queue_data->queue = queue_ref(qe->parent);
6465 queue_data->starttime = starttime;
6466 queue_data->holdstart = holdstart;
6468 queue_data->caller_pos = qe->opos;
6469 ao2_ref(mem, +1);
6470 queue_data->member = mem;
6471
6472 return queue_data;
6473}
6474
6475/*!
6476 * \internal
6477 * \brief Log an attended transfer in the queue log.
6478 *
6479 * Attended transfer queue log messages vary based on the method by which the
6480 * attended transfer was completed.
6481 *
6482 * \param queue_data Data pertaining to the particular call in the queue.
6483 * \param atxfer_msg The stasis attended transfer message data.
6484 */
6485static void log_attended_transfer(struct queue_stasis_data *queue_data,
6486 struct ast_attended_transfer_message *atxfer_msg)
6487{
6488 RAII_VAR(struct ast_str *, transfer_str, ast_str_create(32), ast_free);
6489
6490 if (!transfer_str) {
6491 ast_log(LOG_WARNING, "Unable to log attended transfer to queue log\n");
6492 return;
6493 }
6494
6495 switch (atxfer_msg->dest_type) {
6497 ast_str_set(&transfer_str, 0, "BRIDGE|%s", atxfer_msg->dest.bridge);
6498 break;
6501 ast_str_set(&transfer_str, 0, "APP|%s", atxfer_msg->dest.app);
6502 break;
6504 ast_str_set(&transfer_str, 0, "LINK|%s|%s", atxfer_msg->dest.links[0]->base->name,
6505 atxfer_msg->dest.links[1]->base->name);
6506 break;
6509 /* Threeways are headed off and should not be logged here */
6510 ast_assert(0);
6511 return;
6512 }
6513
6514 ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername, "ATTENDEDTRANSFER", "%s|%ld|%ld|%d",
6515 ast_str_buffer(transfer_str),
6516 (long) (queue_data->starttime - queue_data->holdstart),
6517 (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
6518}
6519
6520/*!
6521 * \internal
6522 * \brief Handle a stasis bridge enter event.
6523 *
6524 * We track this particular event in order to learn what bridge
6525 * was created for the queue call.
6526 *
6527 * \param userdata Data pertaining to the particular call in the queue.
6528 * \param sub The stasis subscription on which the message occurred.
6529 * \param msg The stasis message for the bridge enter event
6530 */
6531static void handle_bridge_enter(void *userdata, struct stasis_subscription *sub,
6532 struct stasis_message *msg)
6533{
6534 struct queue_stasis_data *queue_data = userdata;
6535 struct ast_bridge_blob *enter_blob = stasis_message_data(msg);
6536 SCOPED_AO2LOCK(lock, queue_data);
6537
6538 if (queue_data->dying) {
6539 return;
6540 }
6541
6542 if (!ast_strlen_zero(queue_data->bridge_uniqueid)) {
6543 return;
6544 }
6545
6546 if (!strcmp(enter_blob->channel->base->uniqueid, queue_data->caller_uniqueid)) {
6547 ast_string_field_set(queue_data, bridge_uniqueid,
6548 enter_blob->bridge->uniqueid);
6549 ast_debug(3, "Detected entry of caller channel %s into bridge %s\n",
6550 enter_blob->channel->base->name, queue_data->bridge_uniqueid);
6551 }
6552}
6553
6554/*!
6555 * \brief Handle a blind transfer event
6556 *
6557 * This event is important in order to be able to log the end of the
6558 * call to the queue log and to stasis.
6559 *
6560 * \param userdata Data pertaining to the particular call in the queue.
6561 * \param sub The stasis subscription on which the message occurred.
6562 * \param msg The stasis message for the blind transfer event
6563 */
6564static void handle_blind_transfer(void *userdata, struct stasis_subscription *sub,
6565 struct stasis_message *msg)
6566{
6567 struct queue_stasis_data *queue_data = userdata;
6568 struct ast_blind_transfer_message *transfer_msg = stasis_message_data(msg);
6569 const char *exten;
6570 const char *context;
6571 RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
6572 RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup);
6573
6574 if (transfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS) {
6575 return;
6576 }
6577
6578 ao2_lock(queue_data);
6579
6580 if (queue_data->dying) {
6581 ao2_unlock(queue_data);
6582 return;
6583 }
6584
6585 if (ast_strlen_zero(queue_data->bridge_uniqueid) ||
6586 strcmp(queue_data->bridge_uniqueid, transfer_msg->bridge->uniqueid)) {
6587 ao2_unlock(queue_data);
6588 return;
6589 }
6590
6591 caller_snapshot = ast_channel_snapshot_get_latest(queue_data->caller_uniqueid);
6592 member_snapshot = ast_channel_snapshot_get_latest(queue_data->member_uniqueid);
6593
6594 ao2_unlock(queue_data);
6595
6596 exten = transfer_msg->exten;
6597 context = transfer_msg->context;
6598
6599 ast_debug(3, "Detected blind transfer in queue %s\n", queue_data->queue->name);
6600 ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername,
6601 "BLINDTRANSFER", "%s|%s|%ld|%ld|%d",
6602 exten, context,
6603 (long) (queue_data->starttime - queue_data->holdstart),
6604 (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
6605
6606 send_agent_complete(queue_data->queue->name, caller_snapshot, member_snapshot, queue_data->member,
6607 queue_data->holdstart, queue_data->starttime, TRANSFER);
6608 update_queue(queue_data->queue, queue_data->member, queue_data->callcompletedinsl,
6609 queue_data->starttime);
6610 remove_stasis_subscriptions(queue_data);
6611}
6612
6613/*!
6614 * \brief Handle an attended transfer event
6615 *
6616 * This event is important in order to be able to log the end of the
6617 * call to the queue log and to stasis.
6618 *
6619 * \param userdata Data pertaining to the particular call in the queue.
6620 * \param sub The stasis subscription on which the message occurred.
6621 * \param msg The stasis message for the attended transfer event.
6622 */
6623static void handle_attended_transfer(void *userdata, struct stasis_subscription *sub,
6624 struct stasis_message *msg)
6625{
6626 struct queue_stasis_data *queue_data = userdata;
6627 struct ast_attended_transfer_message *atxfer_msg = stasis_message_data(msg);
6628 RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
6629 RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup);
6630
6631 if (atxfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS ||
6633 return;
6634 }
6635
6636 ao2_lock(queue_data);
6637
6638 if (queue_data->dying) {
6639 ao2_unlock(queue_data);
6640 return;
6641 }
6642
6643 if (ast_strlen_zero(queue_data->bridge_uniqueid)) {
6644 ao2_unlock(queue_data);
6645 return;
6646 }
6647
6648 if ((!atxfer_msg->to_transferee.bridge_snapshot || strcmp(queue_data->bridge_uniqueid,
6649 atxfer_msg->to_transferee.bridge_snapshot->uniqueid)) &&
6650 (!atxfer_msg->to_transfer_target.bridge_snapshot || strcmp(queue_data->bridge_uniqueid,
6652 ao2_unlock(queue_data);
6653 return;
6654 }
6655
6656 caller_snapshot = ast_channel_snapshot_get_latest(queue_data->caller_uniqueid);
6657 member_snapshot = ast_channel_snapshot_get_latest(queue_data->member_uniqueid);
6658
6659 ao2_unlock(queue_data);
6660
6661 ast_debug(3, "Detected attended transfer in queue %s\n", queue_data->queue->name);
6662 log_attended_transfer(queue_data, atxfer_msg);
6663
6664 send_agent_complete(queue_data->queue->name, caller_snapshot, member_snapshot, queue_data->member,
6665 queue_data->holdstart, queue_data->starttime, TRANSFER);
6666 update_queue(queue_data->queue, queue_data->member, queue_data->callcompletedinsl,
6667 queue_data->starttime);
6668 remove_stasis_subscriptions(queue_data);
6669}
6670
6671/*!
6672 * \internal
6673 * \brief Callback for all stasis bridge events
6674 *
6675 * Based on the event and what bridge it is on, the task is farmed out to relevant
6676 * subroutines for further processing.
6677 */
6678static void queue_bridge_cb(void *userdata, struct stasis_subscription *sub,
6679 struct stasis_message *msg)
6680{
6682 ao2_cleanup(userdata);
6683 }
6684}
6685
6686/*!
6687 * \internal
6688 * \brief Handler for the beginning of a local channel optimization
6689 *
6690 * This method gathers data relevant to the local channel optimization and stores
6691 * it to be used once the local optimization completes.
6692 *
6693 * \param userdata Data pertaining to the particular call in the queue.
6694 * \param sub The stasis subscription on which the message occurred.
6695 * \param msg The stasis message for the local optimization begin event
6696 */
6697static void handle_local_optimization_begin(void *userdata, struct stasis_subscription *sub,
6698 struct stasis_message *msg)
6699{
6700 struct queue_stasis_data *queue_data = userdata;
6701 struct ast_multi_channel_blob *optimization_blob = stasis_message_data(msg);
6702 struct ast_channel_snapshot *local_one = ast_multi_channel_blob_get_channel(optimization_blob, "1");
6703 struct ast_channel_snapshot *local_two = ast_multi_channel_blob_get_channel(optimization_blob, "2");
6704 struct ast_channel_snapshot *source = ast_multi_channel_blob_get_channel(optimization_blob, "source");
6705 struct local_optimization *optimization;
6706 unsigned int id;
6707 SCOPED_AO2LOCK(lock, queue_data);
6708
6709 if (!local_one || !local_two || !source) {
6710 ast_debug(1, "Local optimization begin missing channel snapshots:%s%s%s\n",
6711 !local_one ? " local_one," : "",
6712 !local_two ? " local_two," : "",
6713 !source ? " source," : "");
6714 return;
6715 }
6716
6717 if (queue_data->dying) {
6718 return;
6719 }
6720
6721 if (!strcmp(local_one->base->uniqueid, queue_data->member_uniqueid)) {
6722 optimization = &queue_data->member_optimize;
6723 } else if (!strcmp(local_two->base->uniqueid, queue_data->caller_uniqueid)) {
6724 optimization = &queue_data->caller_optimize;
6725 } else {
6726 return;
6727 }
6728
6729 /* We only allow move-swap optimizations, so there had BETTER be a source */
6730 ast_assert(source != NULL);
6731
6732 optimization->source_chan_uniqueid = ast_strdup(source->base->uniqueid);
6733 if (!optimization->source_chan_uniqueid) {
6734 ast_log(LOG_ERROR, "Unable to track local channel optimization for channel %s. Expect further errors\n", local_one->base->name);
6735 return;
6736 }
6738
6739 optimization->id = id;
6740 optimization->in_progress = 1;
6741}
6742
6743/*!
6744 * \internal
6745 * \brief Handler for the end of a local channel optimization
6746 *
6747 * This method takes the data gathered during the local channel optimization begin
6748 * event and applies it to the queue stasis data appropriately. This generally involves
6749 * updating the caller or member unique ID with the channel that is taking the place of
6750 * the previous caller or member.
6751 *
6752 * \param userdata Data pertaining to the particular call in the queue.
6753 * \param sub The stasis subscription on which the message occurred.
6754 * \param msg The stasis message for the local optimization end event
6755 */
6756static void handle_local_optimization_end(void *userdata, struct stasis_subscription *sub,
6757 struct stasis_message *msg)
6758{
6759 struct queue_stasis_data *queue_data = userdata;
6760 struct ast_multi_channel_blob *optimization_blob = stasis_message_data(msg);
6761 struct ast_channel_snapshot *local_one = ast_multi_channel_blob_get_channel(optimization_blob, "1");
6762 struct ast_channel_snapshot *local_two = ast_multi_channel_blob_get_channel(optimization_blob, "2");
6763 struct local_optimization *optimization;
6764 int is_caller;
6765 unsigned int id;
6766 SCOPED_AO2LOCK(lock, queue_data);
6767
6768 if (queue_data->dying) {
6769 return;
6770 }
6771
6772 if (!strcmp(local_one->base->uniqueid, queue_data->member_uniqueid)) {
6773 optimization = &queue_data->member_optimize;
6774 is_caller = 0;
6775 } else if (!strcmp(local_two->base->uniqueid, queue_data->caller_uniqueid)) {
6776 optimization = &queue_data->caller_optimize;
6777 is_caller = 1;
6778 } else {
6779 return;
6780 }
6781
6783
6784 if (!optimization->in_progress) {
6785 ast_log(LOG_WARNING, "Told of a local optimization end when we had no previous begin\n");
6786 return;
6787 }
6788
6789 if (id != optimization->id) {
6790 ast_log(LOG_WARNING, "Local optimization end event ID does not match begin (%u != %u)\n",
6791 id, optimization->id);
6792 return;
6793 }
6794
6795 if (is_caller) {
6796 ast_debug(3, "Local optimization: Changing queue caller uniqueid from %s to %s\n",
6797 queue_data->caller_uniqueid, optimization->source_chan_uniqueid);
6798 ast_string_field_set(queue_data, caller_uniqueid, optimization->source_chan_uniqueid);
6799 } else {
6800 ast_debug(3, "Local optimization: Changing queue member uniqueid from %s to %s\n",
6801 queue_data->member_uniqueid, optimization->source_chan_uniqueid);
6802 ast_string_field_set(queue_data, member_uniqueid, optimization->source_chan_uniqueid);
6803 }
6804
6805 optimization->in_progress = 0;
6806}
6807
6808/*!
6809 * \internal
6810 * \brief Handler for hangup stasis event
6811 *
6812 * This is how we determine that the caller or member has hung up and the call
6813 * has ended. An appropriate queue log and stasis message are raised in this
6814 * callback.
6815 *
6816 * \param userdata Data pertaining to the particular call in the queue.
6817 * \param sub The stasis subscription on which the message occurred.
6818 * \param msg The stasis message for the hangup event.
6819 */
6820static void handle_hangup(void *userdata, struct stasis_subscription *sub,
6821 struct stasis_message *msg)
6822{
6823 struct queue_stasis_data *queue_data = userdata;
6824 struct ast_channel_blob *channel_blob = stasis_message_data(msg);
6825 RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
6826 RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup);
6827 RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup);
6828 enum agent_complete_reason reason;
6829
6830 ao2_lock(queue_data);
6831
6832 if (queue_data->dying) {
6833 ao2_unlock(queue_data);
6834 return;
6835 }
6836
6837 if (!strcmp(channel_blob->snapshot->base->uniqueid, queue_data->caller_uniqueid)) {
6838 reason = CALLER;
6839 } else if (!strcmp(channel_blob->snapshot->base->uniqueid, queue_data->member_uniqueid)) {
6840 reason = AGENT;
6841 } else {
6842 ao2_unlock(queue_data);
6843 return;
6844 }
6845
6846 chan = ast_channel_get_by_name(channel_blob->snapshot->base->name);
6847 if (chan && (ast_channel_has_role(chan, AST_TRANSFERER_ROLE_NAME) ||
6848 !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "ATTENDEDTRANSFER")) ||
6849 !ast_strlen_zero(pbx_builtin_getvar_helper(chan, "BLINDTRANSFER")))) {
6850 /* Channel that is hanging up is doing it as part of a transfer.
6851 * We'll get a transfer event later
6852 */
6853 ao2_unlock(queue_data);
6854 return;
6855 }
6856
6857 caller_snapshot = ast_channel_snapshot_get_latest(queue_data->caller_uniqueid);
6858 member_snapshot = ast_channel_snapshot_get_latest(queue_data->member_uniqueid);
6859
6860 ao2_unlock(queue_data);
6861
6862 ast_debug(3, "Detected hangup of queue %s channel %s\n", reason == CALLER ? "caller" : "member",
6863 channel_blob->snapshot->base->name);
6864
6865 ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername,
6866 reason == CALLER ? "COMPLETECALLER" : "COMPLETEAGENT", "%ld|%ld|%d",
6867 (long) (queue_data->starttime - queue_data->holdstart),
6868 (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
6869
6870 send_agent_complete(queue_data->queue->name, caller_snapshot, member_snapshot, queue_data->member,
6871 queue_data->holdstart, queue_data->starttime, reason);
6872 update_queue(queue_data->queue, queue_data->member, queue_data->callcompletedinsl,
6873 queue_data->starttime);
6874 remove_stasis_subscriptions(queue_data);
6875}
6876
6877static void handle_masquerade(void *userdata, struct stasis_subscription *sub,
6878 struct stasis_message *msg)
6879{
6880 struct queue_stasis_data *queue_data = userdata;
6881 struct ast_channel_blob *channel_blob = stasis_message_data(msg);
6882 const char *new_channel_id;
6883
6884 new_channel_id = ast_json_string_get(ast_json_object_get(channel_blob->blob, "newchanneluniqueid"));
6885
6886 ao2_lock(queue_data);
6887
6888 if (queue_data->dying) {
6889 ao2_unlock(queue_data);
6890 return;
6891 }
6892
6893 if (!strcmp(channel_blob->snapshot->base->uniqueid, queue_data->caller_uniqueid)) {
6894 ast_debug(1, "Replacing caller channel %s with %s due to masquerade\n", queue_data->caller_uniqueid, new_channel_id);
6895 ast_string_field_set(queue_data, caller_uniqueid, new_channel_id);
6896 } else if (!strcmp(channel_blob->snapshot->base->uniqueid, queue_data->member_uniqueid)) {
6897 ast_debug(1, "Replacing member channel %s with %s due to masquerade\n", queue_data->member_uniqueid, new_channel_id);
6898 ast_string_field_set(queue_data, member_uniqueid, new_channel_id);
6899 }
6900
6901 ao2_unlock(queue_data);
6902}
6903
6904/*!
6905 * \internal
6906 * \brief Callback for all stasis channel events
6907 *
6908 * Based on the event and the channels involved, the work is farmed out into
6909 * subroutines for further processing.
6910 */
6911static void queue_channel_cb(void *userdata, struct stasis_subscription *sub,
6912 struct stasis_message *msg)
6913{
6915 ao2_cleanup(userdata);
6916 }
6917}
6918
6919/*!
6920 * \internal
6921 * \brief Create stasis subscriptions for a particular call in the queue.
6922 *
6923 * These subscriptions are created once the call has been answered. The subscriptions
6924 * are put in place so that call progress may be tracked. Once the call can be determined
6925 * to have ended, then messages are logged to the queue log and stasis events are emitted.
6926 *
6927 * \param qe The queue entry representing the caller
6928 * \param peer The channel that has answered the call
6929 * \param mem The queue member that answered the call
6930 * \param holdstart The time at which the caller entered the queue
6931 * \param starttime The time at which the call was answered
6932 * \param callcompletedinsl Indicates if the call was answered within the configured service level of the queue.
6933 * \retval 0 Success
6934 * \retval non-zero Failure
6935 */
6936static int setup_stasis_subs(struct queue_ent *qe, struct ast_channel *peer, struct member *mem,
6937 time_t holdstart, time_t starttime, int callcompletedinsl)
6938{
6939 struct queue_stasis_data *queue_data = queue_stasis_data_alloc(qe, peer, mem, holdstart, starttime, callcompletedinsl);
6940
6941 if (!queue_data) {
6942 return -1;
6943 }
6944
6946 if (!queue_data->bridge_router) {
6947 ao2_ref(queue_data, -1);
6948 return -1;
6949 }
6950
6952 handle_bridge_enter, queue_data);
6954 handle_blind_transfer, queue_data);
6956 handle_attended_transfer, queue_data);
6958 queue_bridge_cb, queue_data);
6959
6961 if (!queue_data->channel_router) {
6962 /* Unsubscribing from the bridge router will remove the only ref of queue_data,
6963 * thus beginning the destruction process
6964 */
6966 queue_data->bridge_router = NULL;
6967 return -1;
6968 }
6969
6970 ao2_ref(queue_data, +1);
6974 handle_local_optimization_end, queue_data);
6976 handle_hangup, queue_data);
6978 handle_masquerade, queue_data);
6980 queue_channel_cb, queue_data);
6981
6982 return 0;
6983}
6984
6986 struct call_queue *q;
6988};
6989
6990static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
6991{
6992 struct queue_end_bridge *qeb = bconfig->end_bridge_callback_data;
6993 ao2_ref(qeb, +1);
6994 qeb->chan = originator;
6995}
6996
6997static void end_bridge_callback(void *data)
6998{
6999 struct queue_end_bridge *qeb = data;
7000 struct call_queue *q = qeb->q;
7001 struct ast_channel *chan = qeb->chan;
7002
7003 if (ao2_ref(qeb, -1) == 1) {
7004 set_queue_variables(q, chan);
7005 /* This unrefs the reference we made in try_calling when we allocated qeb */
7006 queue_t_unref(q, "Expire bridge_config reference");
7007 }
7008}
7009
7010/*!
7011 * \internal
7012 * \brief Setup the after bridge goto location on the peer.
7013 * \since 12.0.0
7014 *
7015 * \param chan Calling channel for bridge.
7016 * \param peer Peer channel for bridge.
7017 * \param opts Dialing option flags.
7018 * \param opt_args Dialing option argument strings.
7019 */
7020static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags *opts, char *opt_args[])
7021{
7022 const char *context;
7023 const char *extension;
7024 int priority;
7025
7026 if (ast_test_flag(opts, OPT_CALLEE_GO_ON)) {
7027 ast_channel_lock(chan);
7031 ast_channel_unlock(chan);
7033 opt_args[OPT_ARG_CALLEE_GO_ON]);
7034 }
7035}
7036
7037static void escape_and_substitute(struct ast_channel *chan, const char *input,
7038 char *output, size_t size)
7039{
7040 const char *m = input;
7041 char escaped[size];
7042 char *p;
7043
7044 for (p = escaped; p < escaped + size - 1; p++, m++) {
7045 switch (*m) {
7046 case '^':
7047 if (*(m + 1) == '{') {
7048 *p = '$';
7049 }
7050 break;
7051 case ',':
7052 *p++ = '\\';
7053 /* Fall through */
7054 default:
7055 *p = *m;
7056 }
7057 if (*m == '\0')
7058 break;
7059 }
7060
7061 if (p == escaped + size) {
7062 escaped[size - 1] = '\0';
7063 }
7064
7065 pbx_substitute_variables_helper(chan, escaped, output, size - 1);
7066}
7067
7068static void setup_mixmonitor(struct queue_ent *qe, const char *filename)
7069{
7070 char escaped_filename[256];
7071 char file_with_ext[sizeof(escaped_filename) + sizeof(qe->parent->monfmt)];
7072 char mixmonargs[1512];
7073 char escaped_monitor_exec[1024];
7074 const char *monitor_options;
7075 const char *monitor_exec;
7076
7077 escaped_monitor_exec[0] = '\0';
7078
7079 if (filename) {
7080 escape_and_substitute(qe->chan, filename, escaped_filename, sizeof(escaped_filename));
7081 } else {
7082 ast_copy_string(escaped_filename, ast_channel_uniqueid(qe->chan), sizeof(escaped_filename));
7083 }
7084
7086 if ((monitor_exec = pbx_builtin_getvar_helper(qe->chan, "MONITOR_EXEC"))) {
7087 monitor_exec = ast_strdupa(monitor_exec);
7088 }
7089 if ((monitor_options = pbx_builtin_getvar_helper(qe->chan, "MONITOR_OPTIONS"))) {
7090 monitor_options = ast_strdupa(monitor_options);
7091 } else {
7092 monitor_options = "";
7093 }
7095
7096 if (monitor_exec) {
7097 escape_and_substitute(qe->chan, monitor_exec, escaped_monitor_exec, sizeof(escaped_monitor_exec));
7098 }
7099
7100 snprintf(file_with_ext, sizeof(file_with_ext), "%s.%s", escaped_filename, qe->parent->monfmt);
7101
7102 if (!ast_strlen_zero(escaped_monitor_exec)) {
7103 snprintf(mixmonargs, sizeof(mixmonargs), "b%s,%s", monitor_options, escaped_monitor_exec);
7104 } else {
7105 snprintf(mixmonargs, sizeof(mixmonargs), "b%s", monitor_options);
7106 }
7107
7108 ast_debug(1, "Arguments being passed to MixMonitor: %s,%s\n", file_with_ext, mixmonargs);
7109
7110 if (ast_start_mixmonitor(qe->chan, file_with_ext, mixmonargs)) {
7111 ast_log(LOG_WARNING, "Unable to start mixmonitor. Is the MixMonitor app loaded?\n");
7112 }
7113}
7114
7115/*!
7116 * \internal
7117 * \brief A large function which calls members, updates statistics, and bridges the caller and a member
7118 *
7119 * Here is the process of this function
7120 * 1. Process any options passed to the Queue() application. Options here mean the third argument to Queue()
7121 * 2. Iterate trough the members of the queue, creating a callattempt corresponding to each member.
7122 * 3. Call ring_one to place a call to the appropriate member(s)
7123 * 4. Call wait_for_answer to wait for an answer. If no one answers, return.
7124 * 5. Take care of any holdtime announcements, member delays, or other options which occur after a call has been answered.
7125 * 6. Start the monitor or mixmonitor if the option is set
7126 * 7. Remove the caller from the queue to allow other callers to advance
7127 * 8. Bridge the call.
7128 * 9. Do any post processing after the call has disconnected.
7129 *
7130 * \param[in] qe the queue_ent structure which corresponds to the caller attempting to reach members
7131 * \param[in] opts the options passed as the third parameter to the Queue() application
7132 * \param[in] opt_args the options passed as the third parameter to the Queue() application
7133 * \param[in] announceoverride filename to play to user when waiting
7134 * \param[in] url the url passed as the fourth parameter to the Queue() application
7135 * \param[in,out] tries the number of times we have tried calling queue members
7136 * \param[out] noption set if the call to Queue() has the 'n' option set.
7137 * \param[in] agi the agi passed as the fifth parameter to the Queue() application
7138 * \param[in] gosub the gosub passed as the sixth parameter to the Queue() application
7139 * \param[in] ringing 1 if the 'r' option is set, otherwise 0
7140 */
7141static int try_calling(struct queue_ent *qe, struct ast_flags opts, char **opt_args, char *announceoverride, const char *url, int *tries, int *noption, const char *agi, const char *gosub, int ringing)
7142{
7143 struct member *cur;
7144 struct callattempt *outgoing = NULL; /* the list of calls we are building */
7145 int to, orig;
7146 char oldexten[AST_MAX_EXTENSION]="";
7147 char oldcontext[AST_MAX_CONTEXT]="";
7148 char queuename[256]="";
7149 struct ast_channel *peer;
7150 struct callattempt *lpeer;
7151 struct member *member;
7152 struct ast_app *application;
7153 int res = 0, bridge = 0;
7154 int numbusies = 0;
7155 int x=0;
7156 char *announce = NULL;
7157 char digit = 0;
7158 time_t now = time(NULL);
7159 struct ast_bridge_config bridge_config;
7160 char nondataquality = 1;
7161 char *agiexec = NULL;
7162 char *gosubexec = NULL;
7163 const char *monitorfilename;
7164 int forwardsallowed = 1;
7165 int block_connected_line = 0;
7166 struct ao2_iterator memi;
7168 int callcompletedinsl;
7169 time_t starttime;
7170
7171 memset(&bridge_config, 0, sizeof(bridge_config));
7172 time(&now);
7173
7174 /* If we've already exceeded our timeout, then just stop
7175 * This should be extremely rare. queue_exec will take care
7176 * of removing the caller and reporting the timeout as the reason.
7177 */
7178 if (qe->expire && now >= qe->expire) {
7179 res = 0;
7180 goto out;
7181 }
7182
7183 if (ast_test_flag(&opts, OPT_CALLEE_TRANSFER)) {
7185 }
7186 if (ast_test_flag(&opts, OPT_CALLER_TRANSFER)) {
7188 }
7189 if (ast_test_flag(&opts, OPT_CALLEE_AUTOMON)) {
7191 }
7192 if (ast_test_flag(&opts, OPT_CALLER_AUTOMON)) {
7194 }
7195 if (ast_test_flag(&opts, OPT_DATA_QUALITY)) {
7196 nondataquality = 0;
7197 }
7198 if (ast_test_flag(&opts, OPT_CALLEE_HANGUP)) {
7200 }
7201 if (ast_test_flag(&opts, OPT_CALLER_HANGUP)) {
7203 }
7204 if (ast_test_flag(&opts, OPT_CALLEE_PARK)) {
7206 }
7207 if (ast_test_flag(&opts, OPT_CALLER_PARK)) {
7209 }
7210 if (ast_test_flag(&opts, OPT_NO_RETRY)) {
7213 (*tries)++;
7214 } else {
7215 *tries = ao2_container_count(qe->parent->members);
7216 }
7217 *noption = 1;
7218 }
7219 if (ast_test_flag(&opts, OPT_IGNORE_CALL_FW)) {
7220 forwardsallowed = 0;
7221 }
7223 block_connected_line = 1;
7224 }
7227 }
7230 }
7231 if (ast_test_flag(&opts, OPT_MARK_AS_ANSWERED)) {
7233 }
7234
7235 /* if the calling channel has AST_CAUSE_ANSWERED_ELSEWHERE set, make sure this is inherited.
7236 (this is mainly to support unreal/local channels)
7237 */
7240 }
7241
7242 ao2_lock(qe->parent);
7243 ast_debug(1, "%s is trying to call a queue member.\n",
7244 ast_channel_name(qe->chan));
7245 ast_copy_string(queuename, qe->parent->name, sizeof(queuename));
7246 if (!ast_strlen_zero(qe->announce)) {
7247 announce = qe->announce;
7248 }
7249 if (!ast_strlen_zero(announceoverride)) {
7250 announce = announceoverride;
7251 }
7252
7253 memi = ao2_iterator_init(qe->parent->members, 0);
7254 while ((cur = ao2_iterator_next(&memi))) {
7255 struct callattempt *tmp = ast_calloc(1, sizeof(*tmp));
7256 if (!tmp) {
7257 ao2_ref(cur, -1);
7258 ao2_iterator_destroy(&memi);
7259 ao2_unlock(qe->parent);
7260 goto out;
7261 }
7262
7263 /*
7264 * Seed the callattempt's connected line information with previously
7265 * acquired connected line info from the queued channel. The
7266 * previously acquired connected line info could have been set
7267 * through the CONNECTED_LINE dialplan function.
7268 */
7272
7273 tmp->block_connected_update = block_connected_line;
7274 tmp->stillgoing = 1;
7275 tmp->member = cur; /* Place the reference for cur into callattempt. */
7276 ast_copy_string(tmp->interface, cur->interface, sizeof(tmp->interface));
7277 /* Calculate the metric for the appropriate strategy. */
7278 if (!calc_metric(qe->parent, cur, x++, qe, tmp)) {
7279 /* Put them in the list of outgoing thingies... We're ready now.
7280 XXX If we're forcibly removed, these outgoing calls won't get
7281 hung up XXX */
7282 tmp->q_next = outgoing;
7283 outgoing = tmp;
7284 } else {
7285 callattempt_free(tmp);
7286 }
7287 }
7288 ao2_iterator_destroy(&memi);
7289
7291 /* Application arguments have higher timeout priority (behaviour for <=1.6) */
7292 if (qe->expire && (!qe->parent->timeout || (qe->expire - now) <= qe->parent->timeout)) {
7293 to = (qe->expire - now) * 1000;
7294 } else {
7295 to = (qe->parent->timeout) ? qe->parent->timeout * 1000 : -1;
7296 }
7297 } else {
7298 /* Config timeout is higher priority thatn application timeout */
7299 if (qe->expire && qe->expire<=now) {
7300 to = 0;
7301 } else if (qe->parent->timeout) {
7302 to = qe->parent->timeout * 1000;
7303 } else {
7304 to = -1;
7305 }
7306 }
7307 orig = to;
7308 ++qe->pending;
7309 ao2_unlock(qe->parent);
7310 /* Call the queue members with the best metric now. */
7311 ring_one(qe, outgoing, &numbusies);
7312 lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies,
7314 forwardsallowed);
7315
7316 ao2_lock(qe->parent);
7319
7320 }
7323 }
7324 ao2_unlock(qe->parent);
7325 peer = lpeer ? lpeer->chan : NULL;
7326 if (!peer) {
7327 qe->pending = 0;
7328 if (to) {
7329 /* Must gotten hung up */
7330 res = -1;
7331 } else {
7332 /* User exited by pressing a digit */
7333 res = digit;
7334 }
7335 if (res == -1) {
7336 ast_debug(1, "%s: Nobody answered.\n", ast_channel_name(qe->chan));
7337 }
7338 } else { /* peer is valid */
7339 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
7340 RAII_VAR(struct ast_str *, interfacevar, ast_str_create(325), ast_free);
7341 /* Ah ha! Someone answered within the desired timeframe. Of course after this
7342 we will always return with -1 so that it is hung up properly after the
7343 conversation. */
7344 if (!strcmp(ast_channel_tech(qe->chan)->type, "DAHDI")) {
7345 ast_channel_setoption(qe->chan, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0);
7346 }
7347 if (!strcmp(ast_channel_tech(peer)->type, "DAHDI")) {
7348 ast_channel_setoption(peer, AST_OPTION_TONE_VERIFY, &nondataquality, sizeof(nondataquality), 0);
7349 }
7350 /* Update parameters for the queue */
7351 time(&now);
7352 recalc_holdtime(qe, (now - qe->start));
7353 member = lpeer->member;
7354 ao2_lock(qe->parent);
7355 callcompletedinsl = member->callcompletedinsl = ((now - qe->start) <= qe->parent->servicelevel);
7356 ao2_unlock(qe->parent);
7357 /* Increment the refcount for this member, since we're going to be using it for awhile in here. */
7358 ao2_ref(member, 1);
7360 outgoing = NULL;
7361 if (announce || qe->parent->reportholdtime || qe->parent->memberdelay) {
7362 int res2;
7363
7364 res2 = ast_autoservice_start(qe->chan);
7365 if (!res2) {
7366 if (qe->parent->memberdelay) {
7367 ast_log(LOG_NOTICE, "Delaying member connect for %d seconds\n", qe->parent->memberdelay);
7368 res2 = ast_safe_sleep(peer, qe->parent->memberdelay * 1000);
7369 }
7370 if (!res2 && announce) {
7371 char *front;
7372 char *announcefiles = ast_strdupa(announce);
7373 while ((front = ast_strsep(&announcefiles, '&', AST_STRSEP_STRIP | AST_STRSEP_TRIM))) {
7374 if (play_file(peer, front) < 0) {
7375 ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", front, ast_channel_name(peer));
7376 }
7377 }
7378 }
7379 if (!res2 && qe->parent->reportholdtime) {
7380 if (!play_file(peer, qe->parent->sound_reporthold)) {
7381 long holdtime, holdtimesecs;
7382
7383 time(&now);
7384 holdtime = labs((now - qe->start) / 60);
7385 holdtimesecs = labs((now - qe->start) % 60);
7386 if (holdtime > 0) {
7387 ast_say_number(peer, holdtime, AST_DIGIT_ANY, ast_channel_language(peer), "n");
7388 if (play_file(peer, qe->parent->sound_minutes) < 0) {
7389 ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_minutes, ast_channel_name(peer));
7390 }
7391 }
7392 if (holdtimesecs > 1) {
7393 ast_say_number(peer, holdtimesecs, AST_DIGIT_ANY, ast_channel_language(peer), "n");
7394 if (play_file(peer, qe->parent->sound_seconds) < 0) {
7395 ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_seconds, ast_channel_name(peer));
7396 }
7397 }
7398 }
7399 }
7401 }
7402 if (ast_check_hangup(peer)) {
7403 /* Agent must have hung up */
7404 ast_log(LOG_WARNING, "Agent on %s hungup on the customer.\n", ast_channel_name(peer));
7405 ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "AGENTDUMP", "%s", "");
7406
7407 blob = ast_json_pack("{s: s, s: s, s: s}",
7408 "Queue", queuename,
7409 "Interface", member->interface,
7410 "MemberName", member->membername);
7411 queue_publish_multi_channel_blob(qe->chan, peer, queue_agent_dump_type(), blob);
7412
7416 ao2_ref(member, -1);
7417 goto out;
7418 } else if (ast_check_hangup(qe->chan)) {
7419 /* Caller must have hung up just before being connected */
7420 ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", ast_channel_name(peer));
7421 ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long) (time(NULL) - qe->start));
7422 record_abandoned(qe);
7423 qe->handled = -1;
7427 ao2_ref(member, -1);
7428 return -1;
7429 }
7430 }
7431 /* Stop music on hold */
7432 if (ringing) {
7433 ast_indicate(qe->chan,-1);
7434 } else {
7435 ast_moh_stop(qe->chan);
7436 }
7437
7438 /* Make sure channels are compatible */
7439 res = ast_channel_make_compatible(qe->chan, peer);
7440 if (res < 0) {
7441 ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "SYSCOMPAT", "%s", "");
7442 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(qe->chan), ast_channel_name(peer));
7443 record_abandoned(qe);
7447 ao2_ref(member, -1);
7448 return -1;
7449 }
7450
7451 /* Play announcement to the caller telling it's his turn if defined */
7453 if (play_file(qe->chan, qe->parent->sound_callerannounce)) {
7454 ast_log(LOG_WARNING, "Announcement file '%s' is unavailable, continuing anyway...\n", qe->parent->sound_callerannounce);
7455 }
7456 }
7457
7458 ao2_lock(qe->parent);
7459 /* if setinterfacevar is defined, make member variables available to the channel */
7460 /* use pbx_builtin_setvar to set a load of variables with one call */
7461 if (qe->parent->setinterfacevar && interfacevar) {
7462 ast_str_set(&interfacevar, 0, "MEMBERINTERFACE=%s,MEMBERNAME=%s,MEMBERCALLS=%d,MEMBERLASTCALL=%ld,MEMBERPENALTY=%d,MEMBERDYNAMIC=%d,MEMBERREALTIME=%d",
7465 pbx_builtin_setvar_multiple(peer, ast_str_buffer(interfacevar));
7466 }
7467
7468 /* if setqueueentryvar is defined, make queue entry (i.e. the caller) variables available to the channel */
7469 /* use pbx_builtin_setvar to set a load of variables with one call */
7470 if (qe->parent->setqueueentryvar && interfacevar) {
7471 ast_str_set(&interfacevar, 0, "QEHOLDTIME=%ld,QEORIGINALPOS=%d",
7472 (long) (time(NULL) - qe->start), qe->opos);
7474 pbx_builtin_setvar_multiple(peer, ast_str_buffer(interfacevar));
7475 }
7476
7477 ao2_unlock(qe->parent);
7478
7479 /* try to set queue variables if configured to do so*/
7481 set_queue_variables(qe->parent, peer);
7482
7483 setup_peer_after_bridge_goto(qe->chan, peer, &opts, opt_args);
7485 if ((monitorfilename = pbx_builtin_getvar_helper(qe->chan, "MONITOR_FILENAME"))) {
7486 monitorfilename = ast_strdupa(monitorfilename);
7487 }
7489
7490 /* Begin Monitoring */
7491 if (*qe->parent->monfmt) {
7492 setup_mixmonitor(qe, monitorfilename);
7493 }
7494 /* Drop out of the queue at this point, to prepare for next caller */
7495 leave_queue(qe);
7497 ast_debug(1, "app_queue: sendurl=%s.\n", url);
7498 ast_channel_sendurl(peer, url);
7499 }
7500
7501 /* run a gosub for this connection if defined. The gosub simply returns, no action is taken on the result */
7502 /* use gosub from dialplan if passed as a option, otherwise use the default queue gosub */
7503 if (!ast_strlen_zero(gosub)) {
7504 gosubexec = ast_strdupa(gosub);
7505 } else {
7506 if (qe->parent->membergosub) {
7507 gosubexec = ast_strdupa(qe->parent->membergosub);
7508 }
7509 }
7510
7511 if (!ast_strlen_zero(gosubexec)) {
7512 char *gosub_args = NULL;
7513 char *gosub_argstart;
7514
7515 ast_debug(1, "app_queue: gosub=%s.\n", gosubexec);
7516
7517 gosub_argstart = strchr(gosubexec, ',');
7518 if (gosub_argstart) {
7519 const char *what_is_s = "s";
7520 *gosub_argstart = 0;
7521 if (!ast_exists_extension(peer, gosubexec, "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
7522 ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
7523 what_is_s = "~~s~~";
7524 }
7525 if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", gosubexec, what_is_s, gosub_argstart + 1) < 0) {
7526 gosub_args = NULL;
7527 }
7528 *gosub_argstart = ',';
7529 } else {
7530 const char *what_is_s = "s";
7531 if (!ast_exists_extension(peer, gosubexec, "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
7532 ast_exists_extension(peer, gosubexec, "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
7533 what_is_s = "~~s~~";
7534 }
7535 if (ast_asprintf(&gosub_args, "%s,%s,1", gosubexec, what_is_s) < 0) {
7536 gosub_args = NULL;
7537 }
7538 }
7539 if (gosub_args) {
7540 ast_app_exec_sub(qe->chan, peer, gosub_args, 0);
7541 ast_free(gosub_args);
7542 } else {
7543 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
7544 }
7545 }
7546
7547 if (!ast_strlen_zero(agi)) {
7548 ast_debug(1, "app_queue: agi=%s.\n", agi);
7549 application = pbx_findapp("agi");
7550 if (application) {
7551 agiexec = ast_strdupa(agi);
7552 pbx_exec(qe->chan, application, agiexec);
7553 } else {
7554 ast_log(LOG_WARNING, "Asked to execute an AGI on this channel, but could not find application (agi)!\n");
7555 }
7556 }
7557 qe->handled++;
7558
7559 ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "CONNECT", "%ld|%s|%ld", (long) (time(NULL) - qe->start), ast_channel_uniqueid(peer),
7560 (long)(orig - to > 0 ? (orig - to) / 1000 : 0));
7561
7562 blob = ast_json_pack("{s: s, s: s, s: s, s: I, s: I}",
7563 "Queue", queuename,
7564 "Interface", member->interface,
7565 "MemberName", member->membername,
7566 "HoldTime", (ast_json_int_t)(time(NULL) - qe->start),
7567 "RingTime", (ast_json_int_t)(orig - to > 0 ? (orig - to) / 1000 : 0));
7568 queue_publish_multi_channel_blob(qe->chan, peer, queue_agent_connect_type(), blob);
7569
7570 ast_copy_string(oldcontext, ast_channel_context(qe->chan), sizeof(oldcontext));
7571 ast_copy_string(oldexten, ast_channel_exten(qe->chan), sizeof(oldexten));
7572
7573 if ((queue_end_bridge = ao2_alloc(sizeof(*queue_end_bridge), NULL))) {
7574 queue_end_bridge->q = qe->parent;
7575 queue_end_bridge->chan = qe->chan;
7579 /* Since queue_end_bridge can survive beyond the life of this call to Queue, we need
7580 * to make sure to increase the refcount of this queue so it cannot be freed until we
7581 * are done with it. We remove this reference in end_bridge_callback.
7582 */
7583 queue_t_ref(qe->parent, "For bridge_config reference");
7584 }
7585
7586 ao2_lock(qe->parent);
7587 time(&member->starttime);
7588 starttime = member->starttime;
7589 ao2_unlock(qe->parent);
7590 /* As a queue member may end up in multiple calls at once if a transfer occurs with
7591 * a Local channel in the mix we pass the current call information (starttime) to the
7592 * Stasis subscriptions so when they update the queue member data it becomes a noop
7593 * if this call is no longer between the caller and the queue member.
7594 */
7595 setup_stasis_subs(qe, peer, member, qe->start, starttime, callcompletedinsl);
7596 bridge = ast_bridge_call_with_flags(qe->chan, peer, &bridge_config,
7598
7599 res = bridge ? bridge : 1;
7600 ao2_ref(member, -1);
7601 }
7602out:
7604
7605 return res;
7606}
7607
7608static int wait_a_bit(struct queue_ent *qe)
7609{
7610 /* Don't need to hold the lock while we setup the outgoing calls */
7611 int retrywait = qe->parent->retry * 1000;
7612
7613 int res = ast_waitfordigit(qe->chan, retrywait);
7614 if (res > 0 && !valid_exit(qe, res)) {
7615 res = 0;
7616 }
7617
7618 return res;
7619}
7620
7621static struct member *interface_exists(struct call_queue *q, const char *interface)
7622{
7623 struct member *mem;
7624 struct ao2_iterator mem_iter;
7625
7626 if (!q) {
7627 return NULL;
7628 }
7629 mem_iter = ao2_iterator_init(q->members, 0);
7630 while ((mem = ao2_iterator_next(&mem_iter))) {
7631 if (!strcasecmp(interface, mem->interface)) {
7632 ao2_iterator_destroy(&mem_iter);
7633 return mem;
7634 }
7635 ao2_ref(mem, -1);
7636 }
7637 ao2_iterator_destroy(&mem_iter);
7638
7639 return NULL;
7640}
7641
7642
7643/*! \brief Dump all members in a specific queue to the database
7644 * \code
7645 * <pm_family>/<queuename> = <interface>;<penalty>;<paused>;<state_interface>[|...]
7646 * \endcode
7647 */
7648static void dump_queue_members(struct call_queue *pm_queue)
7649{
7650 struct member *cur_member;
7651 struct ast_str *value;
7652 struct ao2_iterator mem_iter;
7653
7654 if (!pm_queue) {
7655 return;
7656 }
7657
7658 /* 4K is a reasonable default for most applications, but we grow to
7659 * accommodate more if necessary. */
7660 if (!(value = ast_str_create(4096))) {
7661 return;
7662 }
7663
7664 mem_iter = ao2_iterator_init(pm_queue->members, 0);
7665 while ((cur_member = ao2_iterator_next(&mem_iter))) {
7666 if (!cur_member->dynamic) {
7667 ao2_ref(cur_member, -1);
7668 continue;
7669 }
7670
7671 ast_str_append(&value, 0, "%s%s;%d;%d;%s;%s;%s;%d",
7672 ast_str_strlen(value) ? "|" : "",
7673 cur_member->interface,
7674 cur_member->penalty,
7675 cur_member->paused,
7676 cur_member->membername,
7677 cur_member->state_interface,
7678 cur_member->reason_paused,
7679 cur_member->wrapuptime);
7680
7681 ao2_ref(cur_member, -1);
7682 }
7683 ao2_iterator_destroy(&mem_iter);
7684
7685 if (ast_str_strlen(value) && !cur_member) {
7686 if (ast_db_put(pm_family, pm_queue->name, ast_str_buffer(value))) {
7687 ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n");
7688 }
7689 } else {
7690 /* Delete the entry if the queue is empty or there is an error */
7691 ast_db_del(pm_family, pm_queue->name);
7692 }
7693
7694 ast_free(value);
7695}
7696
7697/*! \brief Remove member from queue
7698 * \retval RES_NOT_DYNAMIC when they aren't a RT member
7699 * \retval RES_NOSUCHQUEUE queue does not exist
7700 * \retval RES_OKAY removed member from queue
7701 * \retval RES_EXISTS queue exists but no members
7702*/
7703static int remove_from_queue(const char *queuename, const char *interface)
7704{
7705 struct call_queue *q, tmpq = {
7706 .name = queuename,
7707 };
7708 struct member *mem, tmpmem;
7709 int res = RES_NOSUCHQUEUE;
7710
7711 ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
7712 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Temporary reference for interface removal"))) {
7713 ao2_lock(q);
7714 if ((mem = ao2_find(q->members, &tmpmem, OBJ_POINTER))) {
7715 /* XXX future changes should beware of this assumption!! */
7716 /*Change Penalty on realtime users*/
7718 update_realtime_member_field(mem, q->name, "penalty", "-1");
7719 } else if (!mem->dynamic) {
7720 ao2_ref(mem, -1);
7721 ao2_unlock(q);
7722 queue_t_unref(q, "Interface wasn't dynamic, expiring temporary reference");
7723 return RES_NOT_DYNAMIC;
7724 }
7725 queue_publish_member_blob(queue_member_removed_type(), queue_member_blob_create(q, mem));
7726
7728 ao2_ref(mem, -1);
7729
7732 }
7733
7734 if (!num_available_members(q)) {
7736 }
7737
7738 res = RES_OKAY;
7739 } else {
7740 res = RES_EXISTS;
7741 }
7742 ao2_unlock(q);
7743 queue_t_unref(q, "Expiring temporary reference");
7744 }
7745
7746 return res;
7747}
7748
7749/*! \brief Add member to queue
7750 * \retval RES_NOT_DYNAMIC when they aren't a RT member
7751 * \retval RES_NOSUCHQUEUE queue does not exist
7752 * \retval RES_OKAY added member from queue
7753 * \retval RES_EXISTS queue exists but no members
7754 * \retval RES_OUT_OF_MEMORY queue exists but not enough memory to create member
7755*/
7756static int add_to_queue(const char *queuename, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface, const char *reason_paused, int wrapuptime)
7757{
7758 struct call_queue *q;
7759 struct member *new_member, *old_member;
7760 int res = RES_NOSUCHQUEUE;
7761
7762 /*! \note Ensure the appropriate realtime queue is loaded. Note that this
7763 * short-circuits if the queue is already in memory. */
7764 if (!(q = find_load_queue_rt_friendly(queuename))) {
7765 return res;
7766 }
7767
7768 ao2_lock(q);
7769 if ((old_member = interface_exists(q, interface)) == NULL) {
7771 new_member->dynamic = 1;
7772 if (reason_paused) {
7773 ast_copy_string(new_member->reason_paused, reason_paused, sizeof(new_member->reason_paused));
7774 }
7775 member_add_to_queue(q, new_member);
7776 queue_publish_member_blob(queue_member_added_type(), queue_member_blob_create(q, new_member));
7777
7778 if (is_member_available(q, new_member)) {
7780 }
7781
7782 ao2_ref(new_member, -1);
7783 new_member = NULL;
7784
7785 if (dump) {
7787 }
7788
7789 res = RES_OKAY;
7790 } else {
7791 res = RES_OUTOFMEMORY;
7792 }
7793 } else {
7794 ao2_ref(old_member, -1);
7795 res = RES_EXISTS;
7796 }
7797 ao2_unlock(q);
7798 queue_t_unref(q, "Expiring temporary reference");
7799
7800 return res;
7801}
7802
7803
7804/*! \brief Change priority caller into a queue
7805 * \retval RES_NOSUCHQUEUE queue does not exist
7806 * \retval RES_OKAY change priority
7807 * \retval RES_NOT_CALLER queue exists but no caller
7808*/
7809static int change_priority_caller_on_queue(const char *queuename, const char *caller, int priority, int immediate)
7810{
7811 struct call_queue *q;
7812 struct queue_ent *current, *prev = NULL, *caller_qe = NULL;
7813 int res = RES_NOSUCHQUEUE;
7814
7815 /*! \note Ensure the appropriate realtime queue is loaded. Note that this
7816 * short-circuits if the queue is already in memory. */
7818 return res;
7819 }
7820
7821 ao2_lock(q);
7823 for (current = q->head; current; current = current->next) {
7824 if (strcmp(ast_channel_name(current->chan), caller) == 0) {
7825 ast_debug(1, "%s Caller new priority %d in queue %s\n",
7826 caller, priority, queuename);
7827 current->prio = priority;
7828 if (immediate) {
7829 /* This caller is being immediately moved in the queue so remove them */
7830 if (prev) {
7831 prev->next = current->next;
7832 } else {
7833 q->head = current->next;
7834 }
7836 /* The position for all callers is not recalculated in here as it will
7837 * be updated when the moved caller is inserted back into the queue
7838 */
7839 }
7840 res = RES_OKAY;
7841 break;
7842 } else if (immediate) {
7843 prev = current;
7844 }
7845 }
7846
7847 if (caller_qe) {
7848 int inserted = 0, pos = 0;
7849
7850 /* If a caller queue entry exists, we are applying their priority immediately
7851 * and have to reinsert them at the correct position.
7852 */
7853 prev = NULL;
7854 current = q->head;
7855 while (current) {
7856 if (!inserted && (caller_qe->prio > current->prio)) {
7857 insert_entry(q, prev, caller_qe, &pos);
7858 inserted = 1;
7859 }
7860
7861 /* We always update the position as it may have changed */
7862 current->pos = ++pos;
7863
7864 /* Move to the next caller in the queue */
7865 prev = current;
7866 current = current->next;
7867 }
7868
7869 if (!inserted) {
7870 insert_entry(q, prev, caller_qe, &pos);
7871 }
7872 }
7873
7874 ao2_unlock(q);
7875 return res;
7876}
7877
7878
7879/*! \brief Request to withdraw a caller from a queue
7880 * \retval RES_NOSUCHQUEUE queue does not exist
7881 * \retval RES_OKAY withdraw request sent
7882 * \retval RES_NOT_CALLER queue exists but no caller
7883 * \retval RES_EXISTS a withdraw request was already sent for this caller (channel) and queue
7884*/
7885static int request_withdraw_caller_from_queue(const char *queuename, const char *caller, const char *withdraw_info)
7886{
7887 struct call_queue *q;
7888 struct queue_ent *qe;
7889 int res = RES_NOSUCHQUEUE;
7890
7891 /*! \note Ensure the appropriate realtime queue is loaded. Note that this
7892 * short-circuits if the queue is already in memory. */
7894 return res;
7895 }
7896
7897 ao2_lock(q);
7899 for (qe = q->head; qe; qe = qe->next) {
7900 if (!strcmp(ast_channel_name(qe->chan), caller)) {
7901 if (qe->withdraw) {
7902 ast_debug(1, "Ignoring duplicate withdraw request of caller %s from queue %s\n", caller, queuename);
7903 res = RES_EXISTS;
7904 } else {
7905 ast_debug(1, "Requested withdraw of caller %s from queue %s\n", caller, queuename);
7906 /* It is not possible to change the withdraw info by further withdraw requests for this caller (channel)
7907 in this queue, so we do not need to worry about a memory leak here. */
7908 if (withdraw_info) {
7909 qe->withdraw_info = ast_strdup(withdraw_info);
7910 }
7911 qe->withdraw = 1;
7912 res = RES_OKAY;
7913 }
7914 break;
7915 }
7916 }
7917 ao2_unlock(q);
7918 queue_unref(q);
7919
7920 return res;
7921}
7922
7923
7925{
7926 struct ast_json *json_blob = queue_member_blob_create(q, member);
7927
7928 if (!json_blob) {
7929 return -1;
7930 }
7931
7932 queue_publish_member_blob(queue_member_pause_type(), json_blob);
7933
7934 return 0;
7935}
7936
7937/*!
7938 * \internal
7939 * \brief Set the pause status of the specific queue member.
7940 *
7941 * \param q Which queue the member belongs.
7942 * \param mem Queue member being paused/unpaused.
7943 * \param reason Why is this happening (Can be NULL/empty for no reason given.)
7944 * \param paused Set to 1 if the member is being paused or 0 to unpause.
7945 *
7946 * \pre The q is locked on entry.
7947 */
7948static void set_queue_member_pause(struct call_queue *q, struct member *mem, const char *reason, int paused)
7949{
7950 if (mem->paused == paused) {
7951 ast_debug(1, "%spausing already-%spaused queue member %s:%s\n",
7952 (paused ? "" : "un"), (paused ? "" : "un"), q->name, mem->interface);
7953 if (log_unpause_on_reason_change && paused) {
7954 if (!ast_strings_equal(mem->reason_paused, reason)) {
7955 ast_queue_log(q->name, "NONE", mem->membername, "UNPAUSE", "%s", "Auto-Unpause");
7956 }
7957 }
7958 }
7959
7960 if (mem->realtime && !ast_strlen_zero(mem->rt_uniqueid)) {
7962 if (ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, "reason_paused", S_OR(reason, ""), "paused", paused ? "1" : "0", SENTINEL) < 0) {
7963 ast_log(LOG_WARNING, "Failed update of realtime queue member %s:%s %spause and reason '%s'\n",
7964 q->name, mem->interface, (paused ? "" : "un"), S_OR(reason, ""));
7965 }
7966 } else {
7967 if (ast_update_realtime("queue_members", "uniqueid", mem->rt_uniqueid, "paused", paused ? "1" : "0", SENTINEL) < 0) {
7968 ast_log(LOG_WARNING, "Failed %spause update of realtime queue member %s:%s\n",
7969 (paused ? "" : "un"), q->name, mem->interface);
7970 }
7971 }
7972 }
7973
7974 mem->paused = paused;
7975 if (paused) {
7976 time(&mem->lastpause); /* update last pause field */
7977 }
7978 if (paused && !ast_strlen_zero(reason)) {
7979 ast_copy_string(mem->reason_paused, reason, sizeof(mem->reason_paused));
7980 } else {
7981 /* We end up filling this in again later (temporarily) but we need it
7982 * empty for now so that the intervening code - specifically
7983 * dump_queue_members() - has the correct view of things. */
7984 mem->reason_paused[0] = '\0';
7985 }
7986
7988 AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, mem->interface);
7989
7992 }
7993
7994 if (is_member_available(q, mem)) {
7996 "Queue:%s_avail", q->name);
7997 } else if (!num_available_members(q)) {
7999 "Queue:%s_avail", q->name);
8000 }
8001
8002 if (!paused && !ast_strlen_zero(reason)) {
8003 /* Because we've been unpaused with a 'reason' we need to ensure that
8004 * that reason is emitted when the subsequent PauseQueueMember event
8005 * is raised. So temporarily set it on the member and clear it out
8006 * again right after. */
8007 ast_copy_string(mem->reason_paused, reason, sizeof(mem->reason_paused));
8008 }
8009
8010 ast_queue_log(q->name, "NONE", mem->membername, paused ? "PAUSE" : "UNPAUSE",
8011 "%s", mem->reason_paused);
8012
8014
8015 if (!paused) {
8016 mem->reason_paused[0] = '\0';
8017 }
8018}
8019
8020static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
8021{
8022 int found = 0;
8023 struct call_queue *q;
8024 struct ao2_iterator queue_iter;
8025
8026 if (ast_check_realtime("queues")) {
8027 load_realtime_queues(queuename);
8028 }
8029
8030 queue_iter = ao2_iterator_init(queues, 0);
8031 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) {
8032 ao2_lock(q);
8033 if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
8034 struct member *mem;
8035
8036 if ((mem = interface_exists(q, interface))) {
8037 /*
8038 * Before we do the PAUSE/UNPAUSE, log if this was a
8039 * PAUSEALL/UNPAUSEALL but only on the first found entry.
8040 */
8041 ++found;
8042 if (found == 1
8043 && ast_strlen_zero(queuename)) {
8044 /*
8045 * XXX In all other cases, we use the queue name,
8046 * but since this affects all queues, we cannot.
8047 */
8048 ast_queue_log("NONE", "NONE", mem->membername,
8049 (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", S_OR(reason, ""));
8050 }
8051
8052 set_queue_member_pause(q, mem, reason, paused);
8053 ao2_ref(mem, -1);
8054 }
8055
8056 if (!ast_strlen_zero(queuename)) {
8057 ao2_unlock(q);
8058 queue_t_unref(q, "Done with iterator");
8059 break;
8060 }
8061 }
8062
8063 ao2_unlock(q);
8064 queue_t_unref(q, "Done with iterator");
8065 }
8066 ao2_iterator_destroy(&queue_iter);
8067
8068 return found ? RESULT_SUCCESS : RESULT_FAILURE;
8069}
8070
8071/*!
8072 * \internal
8073 * \brief helper function for set_member_penalty - given a queue, sets all member penalties with the interface
8074 * \param[in] q queue which is having its member's penalty changed - must be unlocked prior to calling
8075 * \param[in] interface String of interface used to search for queue members being changed
8076 * \param[in] penalty Value penalty is being changed to for the member.
8077 * \retval 0 if the there is no member with interface belonging to q and no change is made
8078 * \retval 1 if the there is a member with interface belonging to q and changes are made
8079 */
8080static int set_member_penalty_help_members(struct call_queue *q, const char *interface, int penalty)
8081{
8082 struct member *mem;
8083 int foundinterface = 0;
8084
8085 ao2_lock(q);
8086 if ((mem = interface_exists(q, interface))) {
8087 foundinterface++;
8088 if (mem->realtime) {
8089 char rtpenalty[80];
8090
8091 sprintf(rtpenalty, "%i", penalty);
8092 update_realtime_member_field(mem, q->name, "penalty", rtpenalty);
8093 }
8094
8095 mem->penalty = penalty;
8096
8097 ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty);
8098 queue_publish_member_blob(queue_member_penalty_type(), queue_member_blob_create(q, mem));
8099 ao2_ref(mem, -1);
8100 }
8101 ao2_unlock(q);
8102
8103 return foundinterface;
8104}
8105
8106/*!
8107 * \internal
8108 * \brief Set the ringinuse value of the specific queue member.
8109 *
8110 * \param q Which queue the member belongs.
8111 * \param mem Queue member being set.
8112 * \param ringinuse Set to 1 if the member is called when inuse.
8113 *
8114 * \pre The q is locked on entry.
8115 */
8116static void set_queue_member_ringinuse(struct call_queue *q, struct member *mem, int ringinuse)
8117{
8118 if (mem->realtime) {
8120 ringinuse ? "1" : "0");
8121 }
8122
8123 mem->ringinuse = ringinuse;
8124
8125 ast_queue_log(q->name, "NONE", mem->interface, "RINGINUSE", "%d", ringinuse);
8126 queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem));
8127}
8128
8130{
8131 struct member *mem;
8132 int foundinterface = 0;
8133
8134 ao2_lock(q);
8135 if ((mem = interface_exists(q, interface))) {
8136 foundinterface++;
8138 ao2_ref(mem, -1);
8139 }
8140 ao2_unlock(q);
8141
8142 return foundinterface;
8143}
8144
8145static int set_member_value_help_members(struct call_queue *q, const char *interface, int property, int value)
8146{
8147 switch(property) {
8148 case MEMBER_PENALTY:
8150
8151 case MEMBER_RINGINUSE:
8153
8154 default:
8155 ast_log(LOG_ERROR, "Attempted to set invalid property\n");
8156 return 0;
8157 }
8158}
8159
8160/*!
8161 * \internal
8162 * \brief Sets members penalty, if queuename=NULL we set member penalty in all the queues.
8163 * \param[in] queuename If specified, only act on a member if it belongs to this queue
8164 * \param[in] interface Interface of queue member(s) having priority set.
8165 * \param[in] property Which queue property is being set
8166 * \param[in] value Value penalty is being changed to for each member
8167 */
8168static int set_member_value(const char *queuename, const char *interface, int property, int value)
8169{
8170 int foundinterface = 0, foundqueue = 0;
8171 struct call_queue *q;
8172 struct ast_config *queue_config = NULL;
8173 struct ao2_iterator queue_iter;
8174
8175 /* property dependent restrictions on values should be checked in this switch */
8176 switch (property) {
8177 case MEMBER_PENALTY:
8178 if (value < 0 && !negative_penalty_invalid) {
8179 ast_log(LOG_ERROR, "Invalid penalty (%d)\n", value);
8180 return RESULT_FAILURE;
8181 }
8182 }
8183
8184 if (ast_strlen_zero(queuename)) { /* This means we need to iterate through all the queues. */
8185 if (ast_check_realtime("queues")) {
8186 queue_config = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
8187 if (queue_config) {
8188 char *category = NULL;
8189 while ((category = ast_category_browse(queue_config, category))) {
8190 const char *name = ast_variable_retrieve(queue_config, category, "name");
8191 if (ast_strlen_zero(name)) {
8192 ast_log(LOG_WARNING, "Ignoring realtime queue with a NULL or empty 'name.'\n");
8193 continue;
8194 }
8195 if ((q = find_load_queue_rt_friendly(name))) {
8196 foundqueue++;
8197 foundinterface += set_member_value_help_members(q, interface, property, value);
8198 queue_unref(q);
8199 }
8200 }
8201
8202 ast_config_destroy(queue_config);
8203 }
8204 }
8205
8206 /* After hitting realtime queues, go back and get the regular ones. */
8207 queue_iter = ao2_iterator_init(queues, 0);
8208 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
8209 foundqueue++;
8210 foundinterface += set_member_value_help_members(q, interface, property, value);
8211 queue_unref(q);
8212 }
8213 ao2_iterator_destroy(&queue_iter);
8214 } else { /* We actually have a queuename, so we can just act on the single queue. */
8215 if ((q = find_load_queue_rt_friendly(queuename))) {
8216 foundqueue++;
8217 foundinterface += set_member_value_help_members(q, interface, property, value);
8218 queue_unref(q);
8219 }
8220 }
8221
8222 if (foundinterface) {
8223 return RESULT_SUCCESS;
8224 } else if (!foundqueue) {
8225 ast_log (LOG_ERROR, "Invalid queuename\n");
8226 } else {
8227 ast_log (LOG_ERROR, "Invalid interface\n");
8228 }
8229
8230 return RESULT_FAILURE;
8231}
8232
8233/*!
8234 * \brief Gets members penalty.
8235 * \return Return the members penalty or RESULT_FAILURE on error.
8236 */
8237static int get_member_penalty(char *queuename, char *interface)
8238{
8239 int foundqueue = 0, penalty;
8240 struct call_queue *q;
8241 struct member *mem;
8242
8243 if ((q = find_load_queue_rt_friendly(queuename))) {
8244 foundqueue = 1;
8245 ao2_lock(q);
8246 if ((mem = interface_exists(q, interface))) {
8247 penalty = mem->penalty;
8248 ao2_ref(mem, -1);
8249 ao2_unlock(q);
8250 queue_t_unref(q, "Search complete");
8251 return penalty;
8252 }
8253 ao2_unlock(q);
8254 queue_t_unref(q, "Search complete");
8255 }
8256
8257 /* some useful debugging */
8258 if (foundqueue) {
8259 ast_log (LOG_ERROR, "Invalid queuename\n");
8260 } else {
8261 ast_log (LOG_ERROR, "Invalid interface\n");
8262 }
8263
8264 return RESULT_FAILURE;
8265}
8266
8267/*! \brief Reload dynamic queue members persisted into the astdb */
8268static void reload_queue_members(void)
8269{
8270 char *cur_ptr;
8271 const char *queue_name;
8272 char *member;
8273 char *interface;
8274 char *membername = NULL;
8275 char *state_interface;
8276 char *penalty_tok;
8277 int penalty = 0;
8278 char *paused_tok;
8279 int paused = 0;
8280 char *wrapuptime_tok;
8281 int wrapuptime = 0;
8282 char *reason_paused;
8283 struct ast_db_entry *db_tree;
8284 struct ast_db_entry *entry;
8285 struct call_queue *cur_queue;
8286 char *queue_data;
8287
8288 /* Each key in 'pm_family' is the name of a queue */
8289 db_tree = ast_db_gettree(pm_family, NULL);
8290 for (entry = db_tree; entry; entry = entry->next) {
8291
8292 queue_name = entry->key + strlen(pm_family) + 2;
8293
8294 {
8295 struct call_queue tmpq = {
8296 .name = queue_name,
8297 };
8298 cur_queue = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Reload queue members");
8299 }
8300
8301 if (!cur_queue) {
8302 cur_queue = find_load_queue_rt_friendly(queue_name);
8303 }
8304
8305 if (!cur_queue) {
8306 /* If the queue no longer exists, remove it from the
8307 * database */
8308 ast_log(LOG_WARNING, "Error loading persistent queue: '%s': it does not exist\n", queue_name);
8309 ast_db_del(pm_family, queue_name);
8310 continue;
8311 }
8312
8313 if (ast_db_get_allocated(pm_family, queue_name, &queue_data)) {
8314 queue_t_unref(cur_queue, "Expire reload reference");
8315 continue;
8316 }
8317
8318 cur_ptr = queue_data;
8319 while ((member = strsep(&cur_ptr, ",|"))) {
8320 if (ast_strlen_zero(member)) {
8321 continue;
8322 }
8323
8324 interface = strsep(&member, ";");
8325 penalty_tok = strsep(&member, ";");
8326 paused_tok = strsep(&member, ";");
8327 membername = strsep(&member, ";");
8328 state_interface = strsep(&member, ";");
8329 reason_paused = strsep(&member, ";");
8330 wrapuptime_tok = strsep(&member, ";");
8331
8332 if (!penalty_tok) {
8333 ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (penalty)\n", queue_name);
8334 break;
8335 }
8336 penalty = strtol(penalty_tok, NULL, 10);
8337 if (errno == ERANGE) {
8338 ast_log(LOG_WARNING, "Error converting penalty: %s: Out of range.\n", penalty_tok);
8339 break;
8340 }
8341
8342 if (!paused_tok) {
8343 ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (paused)\n", queue_name);
8344 break;
8345 }
8346 paused = strtol(paused_tok, NULL, 10);
8347 if ((errno == ERANGE) || paused < 0 || paused > 1) {
8348 ast_log(LOG_WARNING, "Error converting paused: %s: Expected 0 or 1.\n", paused_tok);
8349 break;
8350 }
8351
8352 if (!ast_strlen_zero(wrapuptime_tok)) {
8353 wrapuptime = strtol(wrapuptime_tok, NULL, 10);
8354 if (errno == ERANGE) {
8355 ast_log(LOG_WARNING, "Error converting wrapuptime: %s: Out of range.\n", wrapuptime_tok);
8356 break;
8357 }
8358 }
8359
8360 ast_debug(1, "Reload Members: Queue: %s Member: %s Name: %s Penalty: %d Paused: %d ReasonPause: %s Wrapuptime: %d\n",
8361 queue_name, interface, membername, penalty, paused, reason_paused, wrapuptime);
8362
8363 if (add_to_queue(queue_name, interface, membername, penalty, paused, 0, state_interface, reason_paused, wrapuptime) == RES_OUTOFMEMORY) {
8364 ast_log(LOG_ERROR, "Out of Memory when reloading persistent queue member\n");
8365 break;
8366 }
8367 }
8368 queue_t_unref(cur_queue, "Expire reload reference");
8369 ast_free(queue_data);
8370 }
8371
8372 if (db_tree) {
8373 ast_log(LOG_NOTICE, "Queue members successfully reloaded from database.\n");
8374 ast_db_freetree(db_tree);
8375 }
8376}
8377
8378/*! \brief PauseQueueMember application */
8379static int pqm_exec(struct ast_channel *chan, const char *data)
8380{
8381 char *parse;
8383 AST_APP_ARG(queuename);
8384 AST_APP_ARG(interface);
8386 AST_APP_ARG(reason);
8387 );
8388
8389 if (ast_strlen_zero(data)) {
8390 ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename],interface[,options][,reason])\n");
8391 return -1;
8392 }
8393
8394 parse = ast_strdupa(data);
8395
8397
8398 if (ast_strlen_zero(args.interface)) {
8399 ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename],interface[,options[,reason]])\n");
8400 return -1;
8401 }
8402
8403 if (set_member_paused(args.queuename, args.interface, args.reason, 1)) {
8404 ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", args.interface);
8405 pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND");
8406 return 0;
8407 }
8408
8409 pbx_builtin_setvar_helper(chan, "PQMSTATUS", "PAUSED");
8410
8411 return 0;
8412}
8413
8414/*! \brief UnpauseQueueMember application */
8415static int upqm_exec(struct ast_channel *chan, const char *data)
8416{
8417 char *parse;
8419 AST_APP_ARG(queuename);
8420 AST_APP_ARG(interface);
8422 AST_APP_ARG(reason);
8423 );
8424
8425 if (ast_strlen_zero(data)) {
8426 ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename],interface[,options[,reason]])\n");
8427 return -1;
8428 }
8429
8430 parse = ast_strdupa(data);
8431
8433
8434 if (ast_strlen_zero(args.interface)) {
8435 ast_log(LOG_WARNING, "Missing interface argument to UnpauseQueueMember ([queuename],interface[,options[,reason]])\n");
8436 return -1;
8437 }
8438
8439 if (set_member_paused(args.queuename, args.interface, args.reason, 0)) {
8440 ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", args.interface);
8441 pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND");
8442 return 0;
8443 }
8444
8445 pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "UNPAUSED");
8446
8447 return 0;
8448}
8449
8450/*! \brief RemoveQueueMember application */
8451static int rqm_exec(struct ast_channel *chan, const char *data)
8452{
8453 int res=-1;
8454 char *parse, *temppos = NULL;
8455 struct member *mem = NULL;
8456
8458 AST_APP_ARG(queuename);
8460 );
8461
8462
8463 if (ast_strlen_zero(data)) {
8464 ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[,interface])\n");
8465 return -1;
8466 }
8467
8468 parse = ast_strdupa(data);
8469
8471
8472 if (ast_strlen_zero(args.interface)) {
8473 args.interface = ast_strdupa(ast_channel_name(chan));
8474 temppos = strrchr(args.interface, '-');
8475 if (temppos) {
8476 *temppos = '\0';
8477 }
8478 }
8479
8480 ast_debug(1, "queue: %s, member: %s\n", args.queuename, args.interface);
8481
8483 mem = find_member_by_queuename_and_interface(args.queuename, args.interface);
8484 }
8485
8486 switch (remove_from_queue(args.queuename, args.interface)) {
8487 case RES_OKAY:
8488 if (!mem || ast_strlen_zero(mem->membername)) {
8489 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), args.interface, "REMOVEMEMBER", "%s", "");
8490 } else {
8491 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), mem->membername, "REMOVEMEMBER", "%s", "");
8492 }
8493 ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", args.interface, args.queuename);
8494 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "REMOVED");
8495 res = 0;
8496 break;
8497 case RES_EXISTS:
8498 ast_debug(1, "Unable to remove interface '%s' from queue '%s': Not there\n", args.interface, args.queuename);
8499 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTINQUEUE");
8500 res = 0;
8501 break;
8502 case RES_NOSUCHQUEUE:
8503 ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", args.queuename);
8504 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOSUCHQUEUE");
8505 res = 0;
8506 break;
8507 case RES_NOT_DYNAMIC:
8508 ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': '%s' is not a dynamic member\n", args.queuename, args.interface);
8509 pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTDYNAMIC");
8510 res = 0;
8511 break;
8512 }
8513
8514 if (mem) {
8515 ao2_ref(mem, -1);
8516 }
8517
8518 return res;
8519}
8520
8521/*! \brief AddQueueMember application */
8522static int aqm_exec(struct ast_channel *chan, const char *data)
8523{
8524 int res=-1;
8525 char *parse, *tmp, *temppos = NULL, *reason = NULL;
8527 AST_APP_ARG(queuename);
8534 );
8535 int penalty = 0;
8536 int paused = 0;
8537 int wrapuptime;
8538 struct ast_flags flags = { 0 };
8539
8540 if (ast_strlen_zero(data)) {
8541 ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[,interface[,penalty[,options[,membername[,stateinterface][,wrapuptime]]]]])\n");
8542 return -1;
8543 }
8544
8545 parse = ast_strdupa(data);
8546
8548
8549 if (args.options) {
8550 char *opts[AQM_OPT_ARG_ARRAY_SIZE] = { NULL, };
8551 ast_app_parse_options(aqm_opts, &flags, opts, args.options);
8553 paused = 1;
8555 reason = ast_strdupa(opts[AQM_OPT_ARG_PAUSE_REASON]);
8556 }
8557 }
8558 }
8559
8560 if (ast_strlen_zero(args.interface)) {
8561 args.interface = ast_strdupa(ast_channel_name(chan));
8562 temppos = strrchr(args.interface, '-');
8563 if (temppos) {
8564 *temppos = '\0';
8565 }
8566 }
8567
8568 if (!ast_strlen_zero(args.penalty)) {
8569 if ((sscanf(args.penalty, "%30d", &penalty) != 1) || penalty < 0) {
8570 ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", args.penalty);
8571 penalty = 0;
8572 }
8573 }
8574
8575 if (!ast_strlen_zero(args.wrapuptime)) {
8576 tmp = args.wrapuptime;
8577 ast_strip(tmp);
8578 wrapuptime = atoi(tmp);
8579 if (wrapuptime < 0) {
8580 wrapuptime = 0;
8581 }
8582 } else {
8583 wrapuptime = 0;
8584 }
8585
8586 switch (add_to_queue(args.queuename, args.interface, args.membername, penalty, paused, queue_persistent_members, args.state_interface, reason, wrapuptime)) {
8587 case RES_OKAY:
8588 if (ast_strlen_zero(args.membername) || !log_membername_as_agent) {
8589 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), args.interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
8590 } else {
8591 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), args.membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
8592 }
8593 ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", args.interface, args.queuename);
8594 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "ADDED");
8595 res = 0;
8596 break;
8597 case RES_EXISTS:
8598 ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", args.interface, args.queuename);
8599 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "MEMBERALREADY");
8600 res = 0;
8601 break;
8602 case RES_NOSUCHQUEUE:
8603 ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", args.queuename);
8604 pbx_builtin_setvar_helper(chan, "AQMSTATUS", "NOSUCHQUEUE");
8605 res = 0;
8606 break;
8607 case RES_OUTOFMEMORY:
8608 ast_log(LOG_ERROR, "Out of memory adding interface %s to queue %s\n", args.interface, args.queuename);
8609 break;
8610 }
8611
8612 return res;
8613}
8614
8615/*! \brief QueueLog application */
8616static int ql_exec(struct ast_channel *chan, const char *data)
8617{
8618 char *parse;
8619
8621 AST_APP_ARG(queuename);
8622 AST_APP_ARG(uniqueid);
8623 AST_APP_ARG(membername);
8625 AST_APP_ARG(params);
8626 );
8627
8628 if (ast_strlen_zero(data)) {
8629 ast_log(LOG_WARNING, "QueueLog requires arguments (queuename,uniqueid,membername,event[,additionalinfo]\n");
8630 return -1;
8631 }
8632
8633 parse = ast_strdupa(data);
8634
8636
8637 if (ast_strlen_zero(args.queuename) || ast_strlen_zero(args.uniqueid)
8638 || ast_strlen_zero(args.membername) || ast_strlen_zero(args.event)) {
8639 ast_log(LOG_WARNING, "QueueLog requires arguments (queuename,uniqueid,membername,event[,additionalinfo])\n");
8640 return -1;
8641 }
8642
8643 ast_queue_log(args.queuename, args.uniqueid, args.membername, args.event,
8644 "%s", args.params ? args.params : "");
8645
8646 return 0;
8647}
8648
8649/*! \brief Copy rule from global list into specified queue */
8650static void copy_rules(struct queue_ent *qe, const char *rulename)
8651{
8652 struct penalty_rule *pr_iter;
8653 struct rule_list *rl_iter;
8654 const char *tmp = ast_strlen_zero(rulename) ? qe->parent->defaultrule : rulename;
8656 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) {
8657 if (!strcasecmp(rl_iter->name, tmp)) {
8658 break;
8659 }
8660 }
8661 if (rl_iter) {
8662 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) {
8663 struct penalty_rule *new_pr = ast_calloc(1, sizeof(*new_pr));
8664 if (!new_pr) {
8665 ast_log(LOG_ERROR, "Memory allocation error when copying penalty rules! Aborting!\n");
8666 break;
8667 }
8668 new_pr->time = pr_iter->time;
8669 new_pr->max_value = pr_iter->max_value;
8670 new_pr->min_value = pr_iter->min_value;
8671 new_pr->raise_value = pr_iter->raise_value;
8672 new_pr->max_relative = pr_iter->max_relative;
8673 new_pr->min_relative = pr_iter->min_relative;
8674 new_pr->raise_relative = pr_iter->raise_relative;
8675 AST_LIST_INSERT_TAIL(&qe->qe_rules, new_pr, list);
8676 }
8677 }
8679}
8680
8681/*!\brief The starting point for all queue calls
8682 *
8683 * The process involved here is to
8684 * 1. Parse the options specified in the call to Queue()
8685 * 2. Join the queue
8686 * 3. Wait in a loop until it is our turn to try calling a queue member
8687 * 4. Attempt to call a queue member
8688 * 5. If 4. did not result in a bridged call, then check for between
8689 * call options such as periodic announcements etc.
8690 * 6. Try 4 again unless some condition (such as an expiration time) causes us to
8691 * exit the queue.
8692 */
8693static int queue_exec(struct ast_channel *chan, const char *data)
8694{
8695 int res=-1;
8696 int ringing=0;
8697 const char *user_priority;
8698 const char *max_penalty_str;
8699 const char *min_penalty_str;
8700 const char *raise_penalty_str;
8701 int prio;
8702 int qcontinue = 0;
8703 int max_penalty, min_penalty, raise_penalty;
8704 enum queue_result reason = QUEUE_UNKNOWN;
8705 /* whether to exit Queue application after the timeout hits */
8706 int tries = 0;
8707 int noption = 0;
8708 char *parse;
8709 int makeannouncement = 0;
8710 int position = 0;
8712 AST_APP_ARG(queuename);
8715 AST_APP_ARG(announceoverride);
8716 AST_APP_ARG(queuetimeoutstr);
8717 AST_APP_ARG(agi);
8718 AST_APP_ARG(gosub);
8720 AST_APP_ARG(position);
8721 );
8722 /* Our queue entry */
8723 struct queue_ent qe = { 0 };
8724 struct ast_flags opts = { 0, };
8725 char *opt_args[OPT_ARG_ARRAY_SIZE];
8726 int max_forwards;
8727 int cid_allow;
8728
8729 if (ast_strlen_zero(data)) {
8730 ast_log(LOG_WARNING, "Queue requires an argument: queuename[,options[,URL[,announceoverride[,timeout[,agi[,gosub[,rule[,position]]]]]]]]\n");
8731 return -1;
8732 }
8733
8734 ast_channel_lock(chan);
8736 ast_channel_unlock(chan);
8737
8738 if (max_forwards <= 0) {
8739 ast_log(LOG_WARNING, "Channel '%s' cannot enter queue. Max forwards exceeded\n", ast_channel_name(chan));
8740 return -1;
8741 }
8742
8743 parse = ast_strdupa(data);
8745
8746 ast_debug(1, "queue: %s, options: %s, url: %s, announce: %s, timeout: %s, agi: %s, gosub: %s, rule: %s, position: %s\n",
8747 args.queuename,
8748 S_OR(args.options, ""),
8749 S_OR(args.url, ""),
8750 S_OR(args.announceoverride, ""),
8751 S_OR(args.queuetimeoutstr, ""),
8752 S_OR(args.agi, ""),
8753 S_OR(args.gosub, ""),
8754 S_OR(args.rule, ""),
8755 S_OR(args.position, ""));
8756
8757 if (!ast_strlen_zero(args.options)) {
8758 ast_app_parse_options(queue_exec_options, &opts, opt_args, args.options);
8759 }
8760
8761 /* Setup our queue entry */
8762 qe.start = time(NULL);
8763
8764 pbx_builtin_setvar_helper(chan, "ABANDONED", NULL);
8765
8766 /* set the expire time based on the supplied timeout; */
8767 if (!ast_strlen_zero(args.queuetimeoutstr)) {
8768 qe.expire = qe.start + atoi(args.queuetimeoutstr);
8769 } else {
8770 qe.expire = 0;
8771 }
8772
8773 /* Get the priority from the variable ${QUEUE_PRIO} */
8774 ast_channel_lock(chan);
8775 user_priority = pbx_builtin_getvar_helper(chan, "QUEUE_PRIO");
8776 if (user_priority) {
8777 if (sscanf(user_priority, "%30d", &prio) == 1) {
8778 ast_debug(1, "%s: Got priority %d from ${QUEUE_PRIO}.\n", ast_channel_name(chan), prio);
8779 } else {
8780 ast_log(LOG_WARNING, "${QUEUE_PRIO}: Invalid value (%s), channel %s.\n",
8781 user_priority, ast_channel_name(chan));
8782 prio = 0;
8783 }
8784 } else {
8785 ast_debug(3, "NO QUEUE_PRIO variable found. Using default.\n");
8786 prio = 0;
8787 }
8788
8789 /* Get the maximum penalty from the variable ${QUEUE_MAX_PENALTY} */
8790
8791 if ((max_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MAX_PENALTY"))) {
8792 if (sscanf(max_penalty_str, "%30d", &max_penalty) == 1) {
8793 ast_debug(1, "%s: Got max penalty %d from ${QUEUE_MAX_PENALTY}.\n", ast_channel_name(chan), max_penalty);
8794 } else {
8795 ast_log(LOG_WARNING, "${QUEUE_MAX_PENALTY}: Invalid value (%s), channel %s.\n",
8796 max_penalty_str, ast_channel_name(chan));
8797 max_penalty = INT_MAX;
8798 }
8799 } else {
8800 max_penalty = INT_MAX;
8801 }
8802
8803 if ((min_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MIN_PENALTY"))) {
8804 if (sscanf(min_penalty_str, "%30d", &min_penalty) == 1) {
8805 ast_debug(1, "%s: Got min penalty %d from ${QUEUE_MIN_PENALTY}.\n", ast_channel_name(chan), min_penalty);
8806 } else {
8807 ast_log(LOG_WARNING, "${QUEUE_MIN_PENALTY}: Invalid value (%s), channel %s.\n",
8808 min_penalty_str, ast_channel_name(chan));
8809 min_penalty = INT_MAX;
8810 }
8811 } else {
8812 min_penalty = INT_MAX;
8813 }
8814
8815 if ((raise_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_RAISE_PENALTY"))) {
8816 if (*raise_penalty_str == 'r') {
8817 qe.raise_respect_min = 1;
8818 raise_penalty_str++;
8819 } else {
8820 qe.raise_respect_min = 0;
8821 }
8822 if (sscanf(raise_penalty_str, "%30d", &raise_penalty) == 1) {
8823 ast_debug(1, "%s: Got raise penalty %s%d from ${QUEUE_RAISE_PENALTY}.\n", ast_channel_name(chan), qe.raise_respect_min ? "r" : "", raise_penalty);
8824 } else {
8825 ast_log(LOG_WARNING, "${QUEUE_RAISE_PENALTY}: Invalid value (%s), channel %s.\n",
8826 raise_penalty_str, ast_channel_name(chan));
8827 raise_penalty = INT_MAX;
8828 }
8829 } else {
8830 raise_penalty = INT_MAX;
8831 }
8832 ast_channel_unlock(chan);
8833
8834 if (ast_test_flag(&opts, OPT_RINGING)) {
8835 ringing = 1;
8836 }
8837
8838 if (ringing != 1 && ast_test_flag(&opts, OPT_RING_WHEN_RINGING)) {
8839 qe.ring_when_ringing = 1;
8840 }
8841
8842 if (ast_test_flag(&opts, OPT_GO_ON)) {
8843 qcontinue = 1;
8844 }
8845
8846 if (args.position) {
8847 position = atoi(args.position);
8848 if (position < 0) {
8849 ast_log(LOG_WARNING, "Invalid position '%s' given for call to queue '%s'. Assuming no preference for position\n", args.position, args.queuename);
8850 position = 0;
8851 }
8852 }
8853
8854 ast_debug(1, "queue: %s, expires: %ld, priority: %d\n",
8855 args.queuename, (long)qe.expire, prio);
8856
8857 qe.chan = chan;
8858 qe.prio = prio;
8859 qe.max_penalty = max_penalty;
8860 qe.min_penalty = min_penalty;
8861 qe.raise_penalty = raise_penalty;
8862 qe.last_pos_said = 0;
8863 qe.last_pos = 0;
8866 qe.valid_digits = 0;
8867 if (join_queue(args.queuename, &qe, &reason, position)) {
8868 ast_log(LOG_WARNING, "Unable to join queue '%s'\n", args.queuename);
8869 set_queue_result(chan, reason);
8870 return 0;
8871 }
8872 ast_assert(qe.parent != NULL);
8873
8874 if (qe.parent->periodicannouncestartdelay >= 0) {
8877 }
8878
8880
8881 if (log_caller_id_name) {
8882 char *escaped_cidname = NULL;
8883 /* Ensure caller ID name is valid and not NULL before processing */
8884 if (cid_allow && ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
8885 escaped_cidname = ast_strdupa(ast_channel_caller(chan)->id.name.str);
8886 /* Only iterate if '|' is found */
8887 if (strchr(escaped_cidname, '|')) {
8888 for (char *p = escaped_cidname; *p; p++) {
8889 if (*p == '|') {
8890 *p = '_';
8891 }
8892 }
8893 }
8894 }
8895
8896 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "ENTERQUEUE", "%s|%s|%d|%s",
8897 S_OR(args.url, ""),
8898 S_COR(cid_allow && ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
8899 qe.opos,
8900 S_OR(escaped_cidname, ""));
8901 } else {
8902 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "ENTERQUEUE", "%s|%s|%d",
8903 S_OR(args.url, ""),
8904 S_COR(cid_allow && ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
8905 qe.opos);
8906 }
8907
8908 /* PREDIAL: Preprocess any callee gosub arguments. */
8910 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])) {
8913 }
8914
8915 /* PREDIAL: Run gosub on the caller's channel */
8917 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
8919 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
8920 }
8921
8922 /* Music on hold class override */
8925 ast_copy_string(qe.moh, opt_args[OPT_ARG_MUSICONHOLD_CLASS], sizeof(qe.moh));
8926 }
8927
8928 copy_rules(&qe, args.rule);
8929 qe.pr = AST_LIST_FIRST(&qe.qe_rules);
8930check_turns:
8931 if (ringing) {
8933 } else {
8934 ast_moh_start(chan, qe.moh, NULL);
8935 }
8936
8937 /* This is the wait loop for callers 2 through maxlen */
8938 res = wait_our_turn(&qe, ringing, &reason);
8939 if (res) {
8940 goto stop;
8941 }
8942
8943 makeannouncement = qe.parent->announce_to_first_user;
8944
8945 for (;;) {
8946 /* This is the wait loop for the head caller*/
8947 /* To exit, they may get their call answered; */
8948 /* they may dial a digit from the queue context; */
8949 /* or, they may timeout. */
8950
8951 /* A request to withdraw this call from the queue arrived */
8952 if (qe.withdraw) {
8953 reason = QUEUE_WITHDRAW;
8954 res = 1;
8955 break;
8956 }
8957
8958 /* Leave if we have exceeded our queuetimeout */
8959 if (qe.expire && (time(NULL) >= qe.expire)) {
8960 record_abandoned(&qe);
8961 reason = QUEUE_TIMEOUT;
8962 res = 0;
8963 ast_queue_log(args.queuename, ast_channel_uniqueid(chan),"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld",
8964 qe.pos, qe.opos, (long) (time(NULL) - qe.start));
8965 break;
8966 }
8967
8968 if (makeannouncement) {
8969 /* Make a position announcement, if enabled */
8970 if (qe.parent->announcefrequency) {
8971 if ((res = say_position(&qe, ringing))) {
8972 goto stop;
8973 }
8974 }
8975 }
8976 makeannouncement = 1;
8977
8978 /* Make a periodic announcement, if enabled */
8980 if ((res = say_periodic_announcement(&qe, ringing))) {
8981 goto stop;
8982 }
8983 }
8984
8985 /* A request to withdraw this call from the queue arrived */
8986 if (qe.withdraw) {
8987 reason = QUEUE_WITHDRAW;
8988 res = 1;
8989 break;
8990 }
8991
8992 /* Leave if we have exceeded our queuetimeout */
8993 if (qe.expire && (time(NULL) >= qe.expire)) {
8994 record_abandoned(&qe);
8995 reason = QUEUE_TIMEOUT;
8996 res = 0;
8997 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITWITHTIMEOUT",
8998 "%d|%d|%ld", qe.pos, qe.opos, (long) (time(NULL) - qe.start));
8999 break;
9000 }
9001
9002 /* see if we need to move to the next penalty level for this queue */
9003 while (qe.pr && ((time(NULL) - qe.start) > qe.pr->time)) {
9004 update_qe_rule(&qe);
9005 }
9006
9007 /* Try calling all queue members for 'timeout' seconds */
9008 res = try_calling(&qe, opts, opt_args, args.announceoverride, args.url, &tries, &noption, args.agi, args.gosub, ringing);
9009 if (res) {
9010 goto stop;
9011 }
9012
9013 if (qe.parent->leavewhenempty) {
9014 int status = 0;
9016 record_abandoned(&qe);
9017 reason = QUEUE_LEAVEEMPTY;
9018 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITEMPTY", "%d|%d|%ld", qe.pos, qe.opos, (long)(time(NULL) - qe.start));
9019 res = 0;
9020 break;
9021 }
9022 }
9023
9024 /* exit after 'timeout' cycle if 'n' option enabled */
9025 if (noption && tries >= ao2_container_count(qe.parent->members)) {
9026 ast_verb(3, "Exiting on time-out cycle\n");
9027 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITWITHTIMEOUT",
9028 "%d|%d|%ld", qe.pos, qe.opos, (long) (time(NULL) - qe.start));
9029 record_abandoned(&qe);
9030 reason = QUEUE_TIMEOUT;
9031 res = 0;
9032 break;
9033 }
9034
9035
9036 /* Leave if we have exceeded our queuetimeout */
9037 if (qe.expire && (time(NULL) >= qe.expire)) {
9038 record_abandoned(&qe);
9039 reason = QUEUE_TIMEOUT;
9040 res = 0;
9041 ast_queue_log(qe.parent->name, ast_channel_uniqueid(qe.chan),"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld", qe.pos, qe.opos, (long) (time(NULL) - qe.start));
9042 break;
9043 }
9044
9045 /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */
9046 res = wait_a_bit(&qe);
9047 if (res) {
9048 goto stop;
9049 }
9050
9051 /* If using dynamic realtime members, we should regenerate the member list for this queue */
9053
9054 /* Since this is a priority queue and
9055 * it is not sure that we are still at the head
9056 * of the queue, go and check for our turn again.
9057 */
9058 if (!is_our_turn(&qe)) {
9059 ast_debug(1, "Darn priorities, going back in queue (%s)!\n", ast_channel_name(qe.chan));
9060 goto check_turns;
9061 }
9062 }
9063
9064stop:
9065 if (res) {
9066 if (reason == QUEUE_WITHDRAW) {
9067 record_abandoned(&qe);
9068 ast_queue_log(qe.parent->name, ast_channel_uniqueid(qe.chan), "NONE", "WITHDRAW", "%d|%d|%ld|%.40s", qe.pos, qe.opos, (long) (time(NULL) - qe.start), qe.withdraw_info ? qe.withdraw_info : "");
9069 if (qe.withdraw_info) {
9070 pbx_builtin_setvar_helper(qe.chan, "QUEUE_WITHDRAW_INFO", qe.withdraw_info);
9071 }
9072 res = 0;
9073 } else if (res < 0) {
9074 if (!qe.handled) {
9075 record_abandoned(&qe);
9076 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "ABANDON",
9077 "%d|%d|%ld", qe.pos, qe.opos,
9078 (long) (time(NULL) - qe.start));
9079 res = -1;
9080 } else if (reason == QUEUE_LEAVEEMPTY) {
9081 /* Return back to dialplan, don't hang up */
9082 res = 0;
9083 } else if (qcontinue) {
9084 reason = QUEUE_CONTINUE;
9085 res = 0;
9086 }
9087 } else if (qe.valid_digits) {
9088 ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITWITHKEY",
9089 "%s|%d|%d|%ld", qe.digits, qe.pos, qe.opos, (long) (time(NULL) - qe.start));
9090 }
9091 }
9092
9093 /* Free the optional withdraw info if present */
9094 /* This is done here to catch all cases. e.g. if the call eventually wasn't withdrawn, e.g. answered */
9095 if (qe.withdraw_info) {
9097 qe.withdraw_info = NULL;
9098 }
9099
9100 /* Don't allow return code > 0 */
9101 if (res >= 0) {
9102 res = 0;
9103 if (ringing) {
9104 ast_indicate(chan, -1);
9105 } else {
9106 ast_moh_stop(chan);
9107 }
9108 ast_stopstream(chan);
9109 }
9110
9112
9113 leave_queue(&qe);
9114 if (reason != QUEUE_UNKNOWN)
9115 set_queue_result(chan, reason);
9116
9117 /*
9118 * every queue_ent is given a reference to it's parent
9119 * call_queue when it joins the queue. This ref must be taken
9120 * away right before the queue_ent is destroyed. In this case
9121 * the queue_ent is about to be returned on the stack
9122 */
9123 qe.parent = queue_unref(qe.parent);
9124
9125 return res;
9126}
9127
9128/*!
9129 * \brief create interface var with all queue details.
9130 * \retval 0 on success
9131 * \retval -1 on error
9132*/
9133static int queue_function_var(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9134{
9135 int res = -1;
9136 struct call_queue *q;
9137 char interfacevar[256] = "";
9138 float sl = 0;
9139
9140 if (ast_strlen_zero(data)) {
9141 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
9142 return -1;
9143 }
9144
9145 if ((q = find_load_queue_rt_friendly(data))) {
9146 ao2_lock(q);
9147 if (q->setqueuevar) {
9148 sl = 0;
9149 res = 0;
9150
9151 if (q->callscompleted > 0) {
9152 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
9153 }
9154
9155 snprintf(interfacevar, sizeof(interfacevar),
9156 "QUEUEMAX=%d,QUEUESTRATEGY=%s,QUEUECALLS=%d,QUEUEHOLDTIME=%d,QUEUETALKTIME=%d,QUEUECOMPLETED=%d,QUEUEABANDONED=%d,QUEUESRVLEVEL=%d,QUEUESRVLEVELPERF=%2.1f",
9158
9159 pbx_builtin_setvar_multiple(chan, interfacevar);
9160 }
9161
9162 ao2_unlock(q);
9163 queue_t_unref(q, "Done with QUEUE() function");
9164 } else {
9165 ast_log(LOG_WARNING, "queue %s was not found\n", data);
9166 }
9167
9168 snprintf(buf, len, "%d", res);
9169
9170 return 0;
9171}
9172
9173/*!
9174 * \brief Check if a given queue exists
9175 *
9176 */
9177static int queue_function_exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9178{
9179 struct call_queue *q;
9180
9181 buf[0] = '\0';
9182
9183 if (ast_strlen_zero(data)) {
9184 ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
9185 return -1;
9186 }
9188 snprintf(buf, len, "%d", q != NULL? 1 : 0);
9189 if (q) {
9190 queue_t_unref(q, "Done with temporary reference in QUEUE_EXISTS()");
9191 }
9192
9193 return 0;
9194}
9195
9196static struct member *get_interface_helper(struct call_queue *q, const char *interface)
9197{
9198 struct member *m;
9199
9201 ast_log(LOG_ERROR, "QUEUE_MEMBER: Missing required interface argument.\n");
9202 return NULL;
9203 }
9204
9206 if (!m) {
9207 ast_log(LOG_ERROR, "Queue member interface '%s' not in queue '%s'.\n",
9208 interface, q->name);
9209 }
9210 return m;
9211}
9212
9213/*!
9214 * \brief Get number either busy / free / ready or total members of a specific queue
9215 * \brief Get or set member properties penalty / paused / ringinuse
9216 * \retval number of members (busy / free / ready / total) or member info (penalty / paused / ringinuse)
9217 * \retval -1 on error
9218 */
9219static int queue_function_mem_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9220{
9221 int count = 0;
9222 struct member *m;
9223 struct ao2_iterator mem_iter;
9224 struct call_queue *q;
9225
9227 AST_APP_ARG(queuename);
9228 AST_APP_ARG(option);
9229 AST_APP_ARG(interface);
9230 );
9231 /* Make sure the returned value on error is zero length string. */
9232 buf[0] = '\0';
9233
9234 if (ast_strlen_zero(data)) {
9236 "Missing required argument. %s(<queuename>,<option>[,<interface>])\n",
9237 cmd);
9238 return -1;
9239 }
9240
9242
9243 if (ast_strlen_zero(args.queuename) || ast_strlen_zero(args.option)) {
9245 "Missing required argument. %s(<queuename>,<option>[,<interface>])\n",
9246 cmd);
9247 return -1;
9248 }
9249
9250 if ((q = find_load_queue_rt_friendly(args.queuename))) {
9251 ao2_lock(q);
9252 if (!strcasecmp(args.option, "logged")) {
9253 mem_iter = ao2_iterator_init(q->members, 0);
9254 while ((m = ao2_iterator_next(&mem_iter))) {
9255 /* Count the agents who are logged in and presently answering calls */
9256 if ((m->status != AST_DEVICE_UNAVAILABLE) && (m->status != AST_DEVICE_INVALID)) {
9257 count++;
9258 }
9259 ao2_ref(m, -1);
9260 }
9261 ao2_iterator_destroy(&mem_iter);
9262 } else if (!strcasecmp(args.option, "free")) {
9263 mem_iter = ao2_iterator_init(q->members, 0);
9264 while ((m = ao2_iterator_next(&mem_iter))) {
9265 /* Count the agents who are logged in and presently answering calls */
9266 if ((m->status == AST_DEVICE_NOT_INUSE) && (!m->paused)) {
9267 count++;
9268 }
9269 ao2_ref(m, -1);
9270 }
9271 ao2_iterator_destroy(&mem_iter);
9272 } else if (!strcasecmp(args.option, "ready")) {
9273 time_t now;
9274 time(&now);
9275 mem_iter = ao2_iterator_init(q->members, 0);
9276 while ((m = ao2_iterator_next(&mem_iter))) {
9277 /* Count the agents who are logged in, not paused and not wrapping up */
9278 if ((m->status == AST_DEVICE_NOT_INUSE) && (!m->paused) &&
9279 !(m->lastcall && get_wrapuptime(q, m) && ((now - get_wrapuptime(q, m)) < m->lastcall))) {
9280 count++;
9281 }
9282 ao2_ref(m, -1);
9283 }
9284 ao2_iterator_destroy(&mem_iter);
9285 } else if (!strcasecmp(args.option, "count")) {
9287 } else if (!strcasecmp(args.option, "penalty")) {
9288 m = get_interface_helper(q, args.interface);
9289 if (m) {
9290 count = m->penalty;
9291 ao2_ref(m, -1);
9292 }
9293 } else if (!strcasecmp(args.option, "paused")) {
9294 m = get_interface_helper(q, args.interface);
9295 if (m) {
9296 count = m->paused;
9297 ao2_ref(m, -1);
9298 }
9299 } else if ((!strcasecmp(args.option, "ignorebusy") /* ignorebusy is legacy */
9300 || !strcasecmp(args.option, "ringinuse"))) {
9301 m = get_interface_helper(q, args.interface);
9302 if (m) {
9303 count = m->ringinuse;
9304 ao2_ref(m, -1);
9305 }
9306 } else {
9307 ast_log(LOG_ERROR, "%s: Invalid option '%s' provided.\n", cmd, args.option);
9308 }
9309 ao2_unlock(q);
9310 queue_t_unref(q, "Done with temporary reference in QUEUE_MEMBER()");
9311 } else {
9312 ast_log(LOG_WARNING, "queue %s was not found\n", args.queuename);
9313 }
9314
9315 snprintf(buf, len, "%d", count);
9316
9317 return 0;
9318}
9319
9320/*! \brief Dialplan function QUEUE_MEMBER() Sets the members penalty / paused / ringinuse. */
9321static int queue_function_mem_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
9322{
9323 int memvalue;
9324
9326 AST_APP_ARG(queuename);
9327 AST_APP_ARG(option);
9328 AST_APP_ARG(interface);
9329 );
9330
9331 if (ast_strlen_zero(data)) {
9333 "Missing required argument. %s([<queuename>],<option>,<interface>)\n",
9334 cmd);
9335 return -1;
9336 }
9337
9339
9340 if (ast_strlen_zero(args.option)
9341 || ast_strlen_zero(args.interface)) {
9343 "Missing required argument. %s([<queuename>],<option>,<interface>)\n",
9344 cmd);
9345 return -1;
9346 }
9347
9348 /*
9349 * If queuename is empty then the option will be
9350 * set for the interface in all queues.
9351 */
9352
9353 memvalue = atoi(value);
9354 if (!strcasecmp(args.option, "penalty")) {
9355 if (set_member_value(args.queuename, args.interface, MEMBER_PENALTY, memvalue)) {
9356 ast_log(LOG_ERROR, "Invalid interface, queue, or penalty\n");
9357 return -1;
9358 }
9359 } else if (!strcasecmp(args.option, "paused")) {
9360 memvalue = (memvalue <= 0) ? 0 : 1;
9361 if (set_member_paused(args.queuename, args.interface, NULL, memvalue)) {
9362 ast_log(LOG_ERROR, "Invalid interface or queue\n");
9363 return -1;
9364 }
9365 } else if (!strcasecmp(args.option, "ignorebusy") /* ignorebusy is legacy */
9366 || !strcasecmp(args.option, "ringinuse")) {
9367 memvalue = (memvalue <= 0) ? 0 : 1;
9368 if (set_member_value(args.queuename, args.interface, MEMBER_RINGINUSE, memvalue)) {
9369 ast_log(LOG_ERROR, "Invalid interface or queue\n");
9370 return -1;
9371 }
9372 } else {
9373 ast_log(LOG_ERROR, "%s: Invalid option '%s' provided.\n", cmd, args.option);
9374 return -1;
9375 }
9376 return 0;
9377}
9378
9379/*! \brief Dialplan function QUEUE_GET_CHANNEL() Get caller channel waiting at specified position in the queue */
9380static int queue_function_queuegetchannel(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9381{
9382 int position;
9383 char *parse;
9384 struct call_queue *q;
9385 struct ast_variable *var;
9386
9388 AST_APP_ARG(queuename);
9389 AST_APP_ARG(position);
9390 );
9391
9392 buf[0] = '\0';
9393
9394 if (ast_strlen_zero(data)) {
9395 ast_log(LOG_ERROR, "Missing argument. QUEUE_GET_CHANNEL(<queuename>,<position>)\n");
9396 return -1;
9397 }
9398
9399 parse = ast_strdupa(data);
9401
9402 if (ast_strlen_zero(args.queuename)) {
9403 ast_log (LOG_ERROR, "The <queuename> parameter is required.\n");
9404 return -1;
9405 }
9406
9407 if (ast_strlen_zero(args.position)) {
9408 position = 1;
9409 } else {
9410 if (sscanf(args.position, "%30d", &position) != 1) {
9411 ast_log (LOG_ERROR, "<position> parameter must be an integer.\n");
9412 return -1;
9413 }
9414 if (position < 1) {
9415 ast_log (LOG_ERROR, "<position> parameter must be an integer greater than zero.\n");
9416 return -1;
9417 }
9418 }
9419
9420 {
9421 struct call_queue tmpq = {
9422 .name = args.queuename,
9423 };
9424
9425 q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find for QUEUE_GET_CHANNEL()");
9426 }
9427 if (q) {
9428 ao2_lock(q);
9429 if (q->count >= position) {
9430 struct queue_ent *qe;
9431
9432 for (qe = q->head; qe; qe = qe->next) {
9433 if (qe->pos == position) {
9435 break;
9436 }
9437 }
9438 }
9439 ao2_unlock(q);
9440 queue_t_unref(q, "Done with reference in QUEUE_GET_CHANNEL()");
9441 return 0;
9442 }
9443
9444 var = ast_load_realtime("queues", "name", args.queuename, SENTINEL);
9445 if (var) {
9446 /* if the queue is realtime but was not found in memory, this
9447 * means that the queue had been deleted from memory since it was
9448 * "dead."
9449 */
9451 return 0;
9452 }
9453
9454 ast_log(LOG_WARNING, "queue %s was not found\n", args.queuename);
9455 return 0;
9456}
9457
9458/*! \brief Dialplan function QUEUE_WAITING_COUNT() Get number callers waiting in a specific queue */
9459static int queue_function_queuewaitingcount(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9460{
9461 int count = 0;
9462 struct call_queue *q, tmpq = {
9463 .name = data,
9464 };
9465 struct ast_variable *var = NULL;
9466
9467 buf[0] = '\0';
9468
9469 if (ast_strlen_zero(data)) {
9470 ast_log(LOG_ERROR, "QUEUE_WAITING_COUNT requires an argument: queuename\n");
9471 return -1;
9472 }
9473
9474 if ((q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find for QUEUE_WAITING_COUNT()"))) {
9475 ao2_lock(q);
9476 count = q->count;
9477 ao2_unlock(q);
9478 queue_t_unref(q, "Done with reference in QUEUE_WAITING_COUNT()");
9479 } else if ((var = ast_load_realtime("queues", "name", data, SENTINEL))) {
9480 /* if the queue is realtime but was not found in memory, this
9481 * means that the queue had been deleted from memory since it was
9482 * "dead." This means it has a 0 waiting count
9483 */
9484 count = 0;
9486 } else {
9487 ast_log(LOG_WARNING, "queue %s was not found\n", data);
9488 }
9489
9490 snprintf(buf, len, "%d", count);
9491
9492 return 0;
9493}
9494
9495/*! \brief Dialplan function QUEUE_MEMBER_LIST() Get list of members in a specific queue */
9496static int queue_function_queuememberlist(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9497{
9498 struct call_queue *q;
9499 struct member *m;
9500
9501 /* Ensure an otherwise empty list doesn't return garbage */
9502 buf[0] = '\0';
9503
9504 if (ast_strlen_zero(data)) {
9505 ast_log(LOG_ERROR, "QUEUE_MEMBER_LIST requires an argument: queuename\n");
9506 return -1;
9507 }
9508
9509 if ((q = find_load_queue_rt_friendly(data))) {
9510 int buflen = 0, count = 0;
9511 struct ao2_iterator mem_iter;
9512
9513 ao2_lock(q);
9514 mem_iter = ao2_iterator_init(q->members, 0);
9515 while ((m = ao2_iterator_next(&mem_iter))) {
9516 /* strcat() is always faster than printf() */
9517 if (count++) {
9518 strncat(buf + buflen, ",", len - buflen - 1);
9519 buflen++;
9520 }
9521 strncat(buf + buflen, m->interface, len - buflen - 1);
9522 buflen += strlen(m->interface);
9523 /* Safeguard against overflow (negative length) */
9524 if (buflen >= len - 2) {
9525 ao2_ref(m, -1);
9526 ast_log(LOG_WARNING, "Truncating list\n");
9527 break;
9528 }
9529 ao2_ref(m, -1);
9530 }
9531 ao2_iterator_destroy(&mem_iter);
9532 ao2_unlock(q);
9533 queue_t_unref(q, "Done with QUEUE_MEMBER_LIST()");
9534 } else
9535 ast_log(LOG_WARNING, "queue %s was not found\n", data);
9536
9537 /* We should already be terminated, but let's make sure. */
9538 buf[len - 1] = '\0';
9539
9540 return 0;
9541}
9542
9543/*! \brief Dialplan function QUEUE_MEMBER_PENALTY() Gets the members penalty. */
9544static int queue_function_memberpenalty_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
9545{
9546 int penalty;
9548 AST_APP_ARG(queuename);
9549 AST_APP_ARG(interface);
9550 );
9551 /* Make sure the returned value on error is NULL. */
9552 buf[0] = '\0';
9553
9554 if (ast_strlen_zero(data)) {
9555 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n");
9556 return -1;
9557 }
9558
9560
9561 if (args.argc < 2) {
9562 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n");
9563 return -1;
9564 }
9565
9566 penalty = get_member_penalty (args.queuename, args.interface);
9567
9568 if (penalty >= 0) { /* remember that buf is already '\0' */
9569 snprintf (buf, len, "%d", penalty);
9570 }
9571
9572 return 0;
9573}
9574
9575/*! \brief Dialplan function QUEUE_MEMBER_PENALTY() Sets the members penalty. */
9576static int queue_function_memberpenalty_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
9577{
9578 int penalty;
9580 AST_APP_ARG(queuename);
9581 AST_APP_ARG(interface);
9582 );
9583
9584 if (ast_strlen_zero(data)) {
9585 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n");
9586 return -1;
9587 }
9588
9590
9591 if (args.argc < 2) {
9592 ast_log(LOG_ERROR, "Missing argument. QUEUE_MEMBER_PENALTY(<queuename>,<interface>)\n");
9593 return -1;
9594 }
9595
9596 penalty = atoi(value);
9597
9598 if (ast_strlen_zero(args.interface)) {
9599 ast_log (LOG_ERROR, "<interface> parameter can't be null\n");
9600 return -1;
9601 }
9602
9603 /* if queuename = NULL then penalty will be set for interface in all the queues. */
9604 if (set_member_value(args.queuename, args.interface, MEMBER_PENALTY, penalty)) {
9605 ast_log(LOG_ERROR, "Invalid interface, queue or penalty\n");
9606 return -1;
9607 }
9608
9609 return 0;
9610}
9611
9613 .name = "QUEUE_EXISTS",
9614 .read = queue_function_exists,
9615};
9616
9618 .name = "QUEUE_VARIABLES",
9619 .read = queue_function_var,
9620};
9621
9623 .name = "QUEUE_MEMBER",
9625 .write = queue_function_mem_write,
9626};
9627
9629 .name = "QUEUE_GET_CHANNEL",
9631};
9632
9634 .name = "QUEUE_WAITING_COUNT",
9636};
9637
9639 .name = "QUEUE_MEMBER_LIST",
9641};
9642
9644 .name = "QUEUE_MEMBER_PENALTY",
9647};
9648
9649/*! Reset the global queue rules parameters even if there is no "general" section of queuerules.conf */
9651{
9652 realtime_rules = 0;
9653}
9654
9655/*! Set the global queue rules parameters as defined in the "general" section of queuerules.conf */
9657{
9658 const char *general_val = NULL;
9659 if ((general_val = ast_variable_retrieve(cfg, "general", "realtime_rules"))) {
9660 realtime_rules = ast_true(general_val);
9661 }
9662}
9663
9664/*! \brief Reload the rules defined in queuerules.conf
9665 *
9666 * \param reload If 1, then only process queuerules.conf if the file
9667 * has changed since the last time we inspected it.
9668 * \return Always returns AST_MODULE_LOAD_SUCCESS
9669 */
9671{
9672 struct ast_config *cfg;
9673 struct rule_list *rl_iter, *new_rl;
9674 struct penalty_rule *pr_iter;
9675 char *rulecat = NULL;
9676 struct ast_variable *rulevar = NULL;
9677 struct ast_flags config_flags = { (reload && !realtime_rules) ? CONFIG_FLAG_FILEUNCHANGED : 0 };
9678
9679 if (!(cfg = ast_config_load("queuerules.conf", config_flags))) {
9680 ast_log(LOG_NOTICE, "No queuerules.conf file found, queues will not follow penalty rules\n");
9682 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
9683 ast_log(LOG_NOTICE, "queuerules.conf has not changed since it was last loaded. Not taking any action.\n");
9685 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
9686 ast_log(LOG_ERROR, "Config file queuerules.conf is in an invalid format. Aborting.\n");
9688 }
9689
9691 while ((rl_iter = AST_LIST_REMOVE_HEAD(&rule_lists, list))) {
9692 while ((pr_iter = AST_LIST_REMOVE_HEAD(&rl_iter->rules, list)))
9693 ast_free(pr_iter);
9694 ast_free(rl_iter);
9695 }
9697 while ((rulecat = ast_category_browse(cfg, rulecat))) {
9698 if (!strcasecmp(rulecat, "general")) {
9700 continue;
9701 }
9702 if (!(new_rl = ast_calloc(1, sizeof(*new_rl)))) {
9704 ast_config_destroy(cfg);
9706 } else {
9707 ast_copy_string(new_rl->name, rulecat, sizeof(new_rl->name));
9708 AST_LIST_INSERT_TAIL(&rule_lists, new_rl, list);
9709 for (rulevar = ast_variable_browse(cfg, rulecat); rulevar; rulevar = rulevar->next)
9710 if(!strcasecmp(rulevar->name, "penaltychange"))
9711 insert_penaltychange(new_rl->name, rulevar->value, rulevar->lineno);
9712 else
9713 ast_log(LOG_WARNING, "Don't know how to handle rule type '%s' on line %d\n", rulevar->name, rulevar->lineno);
9714 }
9715 }
9716
9717 ast_config_destroy(cfg);
9718
9722 }
9723
9726}
9727
9728/*! Always set the global queue defaults, even if there is no "general" section in queues.conf */
9740
9741/*! Set the global queue parameters as defined in the "general" section of queues.conf */
9742static void queue_set_global_params(struct ast_config *cfg)
9743{
9744 const char *general_val = NULL;
9745 if ((general_val = ast_variable_retrieve(cfg, "general", "persistentmembers"))) {
9746 queue_persistent_members = ast_true(general_val);
9747 }
9748 if ((general_val = ast_variable_retrieve(cfg, "general", "autofill"))) {
9749 autofill_default = ast_true(general_val);
9750 }
9751 if ((general_val = ast_variable_retrieve(cfg, "general", "monitor-type"))) {
9752 if (!strcasecmp(general_val, "mixmonitor"))
9753 montype_default = 1;
9754 }
9755 if ((general_val = ast_variable_retrieve(cfg, "general", "shared_lastcall"))) {
9756 shared_lastcall = ast_true(general_val);
9757 }
9758 if ((general_val = ast_variable_retrieve(cfg, "general", "negative_penalty_invalid"))) {
9759 negative_penalty_invalid = ast_true(general_val);
9760 }
9761 if ((general_val = ast_variable_retrieve(cfg, "general", "log_membername_as_agent"))) {
9762 log_membername_as_agent = ast_true(general_val);
9763 }
9764 if ((general_val = ast_variable_retrieve(cfg, "general", "force_longest_waiting_caller"))) {
9766 }
9767 if ((general_val = ast_variable_retrieve(cfg, "general", "log_unpause_on_reason_change"))) {
9769 }
9770 /* Apply log-caller-id-name in the same place as other global settings */
9771 if ((general_val = ast_variable_retrieve(cfg, "general", "log-caller-id-name"))) {
9772 log_caller_id_name = ast_true(general_val);
9773 }
9774}
9775
9776/*! \brief reload information pertaining to a single member
9777 *
9778 * This function is called when a member = line is encountered in
9779 * queues.conf.
9780 *
9781 * \param memberdata The part after member = in the config file
9782 * \param q The queue to which this member belongs
9783 */
9784static void reload_single_member(const char *memberdata, struct call_queue *q)
9785{
9786 char *membername, *interface, *state_interface, *tmp;
9787 char *parse;
9788 struct member *cur, *newm;
9789 struct member tmpmem;
9790 int penalty;
9791 int ringinuse;
9792 int wrapuptime;
9793 int paused;
9802 );
9803
9804 if (ast_strlen_zero(memberdata)) {
9805 ast_log(LOG_WARNING, "Empty queue member definition. Moving on!\n");
9806 return;
9807 }
9808
9809 /* Add a new member */
9810 parse = ast_strdupa(memberdata);
9811
9813
9814 interface = args.interface;
9815 if (!ast_strlen_zero(args.penalty)) {
9816 tmp = args.penalty;
9817 ast_strip(tmp);
9818 penalty = atoi(tmp);
9819 if (penalty < 0) {
9820 penalty = 0;
9821 }
9822 } else {
9823 penalty = 0;
9824 }
9825
9826 if (!ast_strlen_zero(args.membername)) {
9827 membername = args.membername;
9828 ast_strip(membername);
9829 } else {
9830 membername = interface;
9831 }
9832
9833 if (!ast_strlen_zero(args.state_interface)) {
9834 state_interface = args.state_interface;
9835 ast_strip(state_interface);
9836 } else {
9837 state_interface = interface;
9838 }
9839
9840 if (!ast_strlen_zero(args.ringinuse)) {
9841 tmp = args.ringinuse;
9842 ast_strip(tmp);
9843 if (ast_true(tmp)) {
9844 ringinuse = 1;
9845 } else if (ast_false(tmp)) {
9846 ringinuse = 0;
9847 } else {
9848 ast_log(LOG_ERROR, "Member %s has an invalid ringinuse value. Using %s ringinuse value.\n",
9849 membername, q->name);
9850 ringinuse = q->ringinuse;
9851 }
9852 } else {
9853 ringinuse = q->ringinuse;
9854 }
9855
9856 if (!ast_strlen_zero(args.wrapuptime)) {
9857 tmp = args.wrapuptime;
9858 ast_strip(tmp);
9859 wrapuptime = atoi(tmp);
9860 if (wrapuptime < 0) {
9861 wrapuptime = 0;
9862 }
9863 } else {
9864 wrapuptime = 0;
9865 }
9866
9867 if (!ast_strlen_zero(args.paused)) {
9868 tmp = args.paused;
9869 ast_strip(tmp);
9870 if (ast_true(tmp)) {
9871 paused = 1;
9872 } else if (ast_false(tmp)) {
9873 paused = 0;
9874 } else {
9875 ast_log(LOG_ERROR, "Member %s has an invalid paused value.\n", membername);
9876 paused = 0;
9877 }
9878 } else {
9879 paused = 0;
9880 }
9881
9882 /* Find the old position in the list */
9883 ast_copy_string(tmpmem.interface, interface, sizeof(tmpmem.interface));
9884 cur = ao2_find(q->members, &tmpmem, OBJ_POINTER);
9885
9886 if (cur) {
9887 paused = cur->paused;
9888 }
9889
9890 if ((newm = create_queue_member(interface, membername, penalty, paused, state_interface, ringinuse, wrapuptime))) {
9891 newm->wrapuptime = wrapuptime;
9892 if (cur) {
9893 ao2_lock(q->members);
9894 /* Round Robin Queue Position must be copied if this is replacing an existing member */
9895 newm->queuepos = cur->queuepos;
9896 /* Don't reset agent stats either */
9897 newm->calls = cur->calls;
9898 newm->lastcall = cur->lastcall;
9899
9900 ao2_link(q->members, newm);
9901 ao2_unlink(q->members, cur);
9902 ao2_unlock(q->members);
9903 } else {
9904 /* Otherwise we need to add using the function that will apply a round robin queue position manually. */
9905 member_add_to_queue(q, newm);
9906 }
9907 ao2_ref(newm, -1);
9908 }
9909 newm = NULL;
9910
9911 if (cur) {
9912 ao2_ref(cur, -1);
9913 }
9914}
9915
9916static int mark_member_dead(void *obj, void *arg, int flags)
9917{
9918 struct member *member = obj;
9919 if (!member->dynamic && !member->realtime) {
9920 member->delme = 1;
9921 }
9922 return 0;
9923}
9924
9925static int kill_dead_members(void *obj, void *arg, int flags)
9926{
9927 struct member *member = obj;
9928
9929 if (!member->delme) {
9931 return 0;
9932 } else {
9933 return CMP_MATCH;
9934 }
9935}
9936
9937/*! \brief Reload information pertaining to a particular queue
9938 *
9939 * Once we have isolated a queue within reload_queues, we call this. This will either
9940 * reload information for the queue or if we're just reloading member information, we'll just
9941 * reload that without touching other settings within the queue
9942 *
9943 * \param cfg The configuration which we are reading
9944 * \param mask Tells us what information we need to reload
9945 * \param queuename The name of the queue we are reloading information from
9946 */
9947static void reload_single_queue(struct ast_config *cfg, struct ast_flags *mask, const char *queuename)
9948{
9949 int new;
9950 struct call_queue *q = NULL;
9951 struct member *member;
9952 /*We're defining a queue*/
9953 struct call_queue tmpq = {
9954 .name = queuename,
9955 };
9956 const char *tmpvar;
9957 const int queue_reload = ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS);
9958 const int member_reload = ast_test_flag(mask, QUEUE_RELOAD_MEMBER);
9959 int prev_weight = 0;
9960 struct ast_variable *var;
9961 struct ao2_iterator mem_iter;
9962
9963 if (!(q = ao2_t_find(queues, &tmpq, OBJ_POINTER, "Find queue for reload"))) {
9964 if (queue_reload) {
9965 /* Make one then */
9966 if (!(q = alloc_queue(queuename))) {
9967 return;
9968 }
9969 } else {
9970 /* Since we're not reloading queues, this means that we found a queue
9971 * in the configuration file which we don't know about yet. Just return.
9972 */
9973 return;
9974 }
9975 new = 1;
9976 } else {
9977 new = 0;
9978 }
9979
9980 if (!new) {
9981 ao2_lock(q);
9982 prev_weight = q->weight ? 1 : 0;
9983 }
9984 /* Check if we already found a queue with this name in the config file */
9985 if (q->found) {
9986 ast_log(LOG_WARNING, "Queue '%s' already defined! Skipping!\n", queuename);
9987 if (!new) {
9988 /* It should be impossible to *not* hit this case*/
9989 ao2_unlock(q);
9990 }
9991 queue_t_unref(q, "We exist! Expiring temporary pointer");
9992 return;
9993 }
9994 /* Due to the fact that the "linear" strategy will have a different allocation
9995 * scheme for queue members, we must devise the queue's strategy before other initializations.
9996 * To be specific, the linear strategy needs to function like a linked list, meaning the ao2
9997 * container used will have only a single bucket instead of the typical number.
9998 */
9999 if (queue_reload) {
10000 if ((tmpvar = ast_variable_retrieve(cfg, queuename, "strategy"))) {
10001 q->strategy = strat2int(tmpvar);
10002 if (q->strategy < 0) {
10003 ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n",
10004 tmpvar, q->name);
10006 }
10007 } else {
10009 }
10010 init_queue(q);
10011 }
10012 if (member_reload) {
10014 q->found = 1;
10015 }
10016
10017 /* On the first pass we just read the parameters of the queue */
10018 for (var = ast_variable_browse(cfg, queuename); var; var = var->next) {
10019 if (queue_reload && strcasecmp(var->name, "member")) {
10020 queue_set_param(q, var->name, var->value, var->lineno, 1);
10021 }
10022 }
10023
10024 /* On the second pass, we read members */
10025 for (var = ast_variable_browse(cfg, queuename); var; var = var->next) {
10026 if (member_reload && !strcasecmp(var->name, "member")) {
10027 reload_single_member(var->value, q);
10028 }
10029 }
10030
10031 /* Update ringinuse for dynamic members */
10032 if (member_reload) {
10033 ao2_lock(q->members);
10035 while ((member = ao2_iterator_next(&mem_iter))) {
10036 if (member->dynamic) {
10038 }
10039 ao2_ref(member, -1);
10040 }
10041 ao2_iterator_destroy(&mem_iter);
10042 ao2_unlock(q->members);
10043 }
10044
10045 /* At this point, we've determined if the queue has a weight, so update use_weight
10046 * as appropriate
10047 */
10048 if (!q->weight && prev_weight) {
10050 } else if (q->weight && !prev_weight) {
10052 }
10053
10054 /* Free remaining members marked as delme */
10055 if (member_reload) {
10056 ao2_lock(q->members);
10059 ao2_unlock(q->members);
10060 }
10061
10062 if (new) {
10063 queues_t_link(queues, q, "Add queue to container");
10064 } else {
10065 ao2_unlock(q);
10066 }
10067 queue_t_unref(q, "Expiring creation reference");
10068}
10069
10070static int mark_unfound(void *obj, void *arg, int flags)
10071{
10072 struct call_queue *q = obj;
10073 char *queuename = arg;
10074 if (!q->realtime && (ast_strlen_zero(queuename) || !strcasecmp(queuename, q->name))) {
10075 q->found = 0;
10076 }
10077 return 0;
10078}
10079
10080static int kill_if_unfound(void *obj, void *arg, int flags)
10081{
10082 struct call_queue *q = obj;
10083 char *queuename = arg;
10084 if (!q->realtime && !q->found && (ast_strlen_zero(queuename) || !strcasecmp(queuename, q->name))) {
10085 q->dead = 1;
10086 return CMP_MATCH;
10087 } else {
10088 return 0;
10089 }
10090}
10091
10092/*! \brief reload the queues.conf file
10093 *
10094 * This function reloads the information in the general section of the queues.conf
10095 * file and potentially more, depending on the value of mask.
10096 *
10097 * \param reload 0 if we are calling this the first time, 1 every other time
10098 * \param mask Gives flags telling us what information to actually reload
10099 * \param queuename If set to a non-zero string, then only reload information from
10100 * that particular queue. Otherwise inspect all queues
10101 * \retval -1 Failure occurred
10102 * \retval 0 All clear!
10103 */
10104static int reload_queues(int reload, struct ast_flags *mask, const char *queuename)
10105{
10106 struct ast_config *cfg;
10107 char *cat;
10108 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
10109 const int queue_reload = ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS);
10110
10111 if (!(cfg = ast_config_load("queues.conf", config_flags))) {
10112 ast_log(LOG_NOTICE, "No call queueing config file (queues.conf), so no call queues\n");
10113 return -1;
10114 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
10115 return 0;
10116 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
10117 ast_log(LOG_ERROR, "Config file queues.conf is in an invalid format. Aborting.\n");
10118 return -1;
10119 }
10120
10121 /* We've made it here, so it looks like we're doing operations on all queues. */
10123
10124 /* Mark non-realtime queues not found at the beginning. */
10125 ao2_callback(queues, OBJ_NODATA, mark_unfound, (char *) queuename);
10126
10127 /* Chug through config file. */
10128 cat = NULL;
10130 while ((cat = ast_category_browse(cfg, cat)) ) {
10131 if (!strcasecmp(cat, "general") && queue_reload) {
10133 continue;
10134 }
10135 if (ast_strlen_zero(queuename) || !strcasecmp(cat, queuename))
10136 reload_single_queue(cfg, mask, cat);
10137 }
10138
10139 ast_config_destroy(cfg);
10140 if (queue_reload) {
10141 /* Unlink and mark dead all non-realtime queues that were not found in the configuration file. */
10143 }
10145 return 0;
10146}
10147
10148/*! \brief Facilitates resetting statistics for a queue
10149 *
10150 * This function actually does not reset any statistics, but
10151 * rather finds a call_queue struct which corresponds to the
10152 * passed-in queue name and passes that structure to the
10153 * clear_queue function. If no queuename is passed in, then
10154 * all queues will have their statistics reset.
10155 *
10156 * \param queuename The name of the queue to reset the statistics
10157 * for. If this is NULL or zero-length, then this means to reset
10158 * the statistics for all queues
10159 * \retval 0 always
10160 */
10161static int clear_stats(const char *queuename)
10162{
10163 struct call_queue *q;
10164 struct ao2_iterator queue_iter;
10165
10166 queue_iter = ao2_iterator_init(queues, 0);
10167 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
10168 ao2_lock(q);
10169 if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename))
10170 clear_queue(q);
10171 ao2_unlock(q);
10172 queue_t_unref(q, "Done with iterator");
10173 }
10174 ao2_iterator_destroy(&queue_iter);
10175 return 0;
10176}
10177
10178/*! \brief The command center for all reload operations
10179 *
10180 * Whenever any piece of queue information is to be reloaded, this function
10181 * is called. It interprets the flags set in the mask parameter and acts
10182 * based on how they are set.
10183 *
10184 * \param reload True if we are reloading information, false if we are loading
10185 * information for the first time.
10186 * \param mask A bitmask which tells the handler what actions to take
10187 * \param queuename The name of the queue on which we wish to take action
10188 * \retval 0 All reloads were successful
10189 * \retval non-zero There was a failure
10190 */
10191static int reload_handler(int reload, struct ast_flags *mask, const char *queuename)
10192{
10193 int res = 0;
10194
10195 if (ast_test_flag(mask, QUEUE_RELOAD_RULES)) {
10196 res |= reload_queue_rules(reload);
10197 }
10198 if (ast_test_flag(mask, QUEUE_RESET_STATS)) {
10199 res |= clear_stats(queuename);
10200 }
10202 res |= reload_queues(reload, mask, queuename);
10203 }
10204 return res;
10205}
10206
10207/*! \brief direct output to manager or cli with proper terminator */
10208static void do_print(struct mansession *s, int fd, const char *str)
10209{
10210 if (s) {
10211 astman_append(s, "%s\r\n", str);
10212 } else {
10213 ast_cli(fd, "%s\n", str);
10214 }
10215}
10216
10217/*! \brief Print a single queue to AMI or the CLI */
10218static void print_queue(struct mansession *s, int fd, struct call_queue *q)
10219{
10220 float sl;
10221 float sl2;
10222 struct ao2_iterator mem_iter;
10223 struct ast_str *out = ast_str_alloca(512);
10224 time_t now = time(NULL);
10225
10226 ast_str_set(&out, 0, "%s has %d calls (max ", q->name, q->count);
10227 if (q->maxlen) {
10228 ast_str_append(&out, 0, "%d", q->maxlen);
10229 } else {
10230 ast_str_append(&out, 0, "unlimited");
10231 }
10232 sl = 0;
10233 sl2 = 0;
10234 if (q->callscompleted > 0) {
10235 sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
10236 }
10237 if (q->callscompleted + q->callsabandoned > 0) {
10238 sl2 =100 * (((float)q->callsabandonedinsl + (float)q->callscompletedinsl) / ((float)q->callsabandoned + (float)q->callscompleted));
10239 }
10240
10241 ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime, %ds talktime), W:%d, C:%d, A:%d, SL:%2.1f%%, SL2:%2.1f%% within %ds",
10243 do_print(s, fd, ast_str_buffer(out));
10244 if (!ao2_container_count(q->members)) {
10245 do_print(s, fd, " No Members");
10246 } else {
10247 struct member *mem;
10248
10249 do_print(s, fd, " Members: ");
10250 mem_iter = ao2_iterator_init(q->members, 0);
10251 while ((mem = ao2_iterator_next(&mem_iter))) {
10252 ast_str_set(&out, 0, " %s", mem->membername);
10253 if (strcasecmp(mem->membername, mem->interface)) {
10254 ast_str_append(&out, 0, " (%s", mem->interface);
10256 && strcmp(mem->state_interface, mem->interface)) {
10257 ast_str_append(&out, 0, " from %s", mem->state_interface);
10258 }
10259 ast_str_append(&out, 0, ")");
10260 }
10261 if (mem->penalty) {
10262 ast_str_append(&out, 0, " with penalty %d", mem->penalty);
10263 }
10264
10265 ast_str_append(&out, 0, " (ringinuse %s)", mem->ringinuse ? "enabled" : "disabled");
10266
10267 ast_str_append(&out, 0, "%s%s%s%s%s%s%s%s%s",
10268 mem->dynamic ? ast_term_color(COLOR_CYAN, COLOR_BLACK) : "", mem->dynamic ? " (dynamic)" : "", ast_term_reset(),
10269 mem->realtime ? ast_term_color(COLOR_MAGENTA, COLOR_BLACK) : "", mem->realtime ? " (realtime)" : "", ast_term_reset(),
10270 mem->starttime ? ast_term_color(COLOR_BROWN, COLOR_BLACK) : "", mem->starttime ? " (in call)" : "", ast_term_reset());
10271
10272 if (mem->paused) {
10273 ast_str_append(&out, 0, " %s(paused%s%s was %ld secs ago)%s",
10275 ast_strlen_zero(mem->reason_paused) ? "" : ":",
10277 (long) (now - mem->lastpause),
10278 ast_term_reset());
10279 }
10280
10281 ast_str_append(&out, 0, " (%s%s%s)",
10286 if (mem->calls) {
10287 ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)",
10288 mem->calls, (long) (now - mem->lastcall));
10289 } else {
10290 ast_str_append(&out, 0, " has taken no calls yet");
10291 }
10292 ast_str_append(&out, 0, " %s(login was %ld secs ago)%s",
10294 (long) (now - mem->logintime),
10295 ast_term_reset());
10296 do_print(s, fd, ast_str_buffer(out));
10297 ao2_ref(mem, -1);
10298 }
10299 ao2_iterator_destroy(&mem_iter);
10300 }
10301 if (!q->head) {
10302 do_print(s, fd, " No Callers");
10303 } else {
10304 struct queue_ent *qe;
10305 int pos = 1;
10306
10307 do_print(s, fd, " Callers: ");
10308 for (qe = q->head; qe; qe = qe->next) {
10309 ast_str_set(&out, 0, " %d. %s (wait: %ld:%2.2ld, prio: %d)",
10310 pos++, ast_channel_name(qe->chan), (long) (now - qe->start) / 60,
10311 (long) (now - qe->start) % 60, qe->prio);
10312 do_print(s, fd, ast_str_buffer(out));
10313 }
10314 }
10315 do_print(s, fd, ""); /* blank line between entries */
10316}
10317
10319
10320/*!
10321 * \brief Show queue(s) status and statistics
10322 *
10323 * List the queues strategy, calls processed, members logged in,
10324 * other queue statistics such as avg hold time.
10325*/
10326static char *__queues_show(struct mansession *s, int fd, int argc, const char * const *argv)
10327{
10328 struct call_queue *q;
10329 struct ast_str *out = ast_str_alloca(512);
10330 struct ao2_container *sorted_queues;
10331
10332 struct ao2_iterator queue_iter;
10333 int found = 0;
10334
10335 if (argc != 2 && argc != 3) {
10336 return CLI_SHOWUSAGE;
10337 }
10338
10339 if (argc == 3) { /* specific queue */
10340 if ((q = find_load_queue_rt_friendly(argv[2]))) {
10341 ao2_lock(q);
10342 print_queue(s, fd, q);
10343 ao2_unlock(q);
10344 queue_unref(q);
10345 } else {
10346 ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
10347 do_print(s, fd, ast_str_buffer(out));
10348 }
10349 return CLI_SUCCESS;
10350 }
10351
10352 if (ast_check_realtime("queues")) {
10353 /* This block is to find any queues which are defined in realtime but
10354 * which have not yet been added to the in-core container
10355 */
10356 struct ast_config *cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
10357 if (cfg) {
10358 char *category = NULL;
10359 while ((category = ast_category_browse(cfg, category))) {
10360 const char *queuename = ast_variable_retrieve(cfg, category, "name");
10361 if (ast_strlen_zero(queuename)) {
10362 ast_log(LOG_WARNING, "Ignoring realtime queue with a NULL or empty 'name.'\n");
10363 continue;
10364 }
10365 if ((q = find_load_queue_rt_friendly(queuename))) {
10366 queue_t_unref(q, "Done with temporary pointer");
10367 }
10368 }
10369 ast_config_destroy(cfg);
10370 }
10371 }
10372
10373 /*
10374 * Snapping a copy of the container prevents having to lock both the queues container
10375 * and the queue itself at the same time. It also allows us to sort the entries.
10376 */
10377 sorted_queues = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, call_queue_sort_fn, NULL);
10378 if (!sorted_queues) {
10379 return CLI_SUCCESS;
10380 }
10381 if (ao2_container_dup(sorted_queues, queues, 0)) {
10382 ao2_ref(sorted_queues, -1);
10383 return CLI_SUCCESS;
10384 }
10385
10386 /*
10387 * No need to lock the container since it's temporary and static.
10388 * We also unlink the entries as we use them so the container is
10389 * empty when the iterator finishes. We can then just unref the container.
10390 */
10391 queue_iter = ao2_iterator_init(sorted_queues, AO2_ITERATOR_DONTLOCK | AO2_ITERATOR_UNLINK);
10392 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
10393 struct call_queue *realtime_queue = NULL;
10394 ao2_lock(q);
10395 /* This check is to make sure we don't print information for realtime
10396 * queues which have been deleted from realtime but which have not yet
10397 * been deleted from the in-core container. Only do this if we're not
10398 * looking for a specific queue.
10399 */
10400 if (q->realtime) {
10401 realtime_queue = find_load_queue_rt_friendly(q->name);
10402 if (!realtime_queue) {
10403 ao2_unlock(q);
10404 queue_t_unref(q, "Done with iterator");
10405 continue;
10406 }
10407 queue_t_unref(realtime_queue, "Queue is already in memory");
10408 }
10409
10410 found = 1;
10411 print_queue(s, fd, q);
10412
10413 ao2_unlock(q);
10414 queue_t_unref(q, "Done with iterator"); /* Unref the iterator's reference */
10415 }
10416 ao2_iterator_destroy(&queue_iter);
10417 ao2_ref(sorted_queues, -1);
10418 if (!found) {
10419 ast_str_set(&out, 0, "No queues.");
10420 do_print(s, fd, ast_str_buffer(out));
10421 }
10422 return CLI_SUCCESS;
10423}
10424
10425/*!
10426 * \brief Check if a given word is in a space-delimited list
10427 *
10428 * \param list Space delimited list of words
10429 * \param word The word used to search the list
10430 *
10431 * \note This function will not return 1 if the word is at the very end of the
10432 * list (followed immediately by a \0, not a space) since it is used for
10433 * checking tab-completion and a word at the end is still being tab-completed.
10434 *
10435 * \retval 1 if the word is found
10436 * \retval 0 if the word is not found
10437*/
10438static int word_in_list(const char *list, const char *word) {
10439 int list_len, word_len = strlen(word);
10440 const char *find, *end_find, *end_list;
10441
10442 /* strip whitespace from front */
10443 while(isspace(*list)) {
10444 list++;
10445 }
10446
10447 while((find = strstr(list, word))) {
10448 /* beginning of find starts inside another word? */
10449 if (find != list && *(find - 1) != ' ') {
10450 list = find;
10451 /* strip word from front */
10452 while(!isspace(*list) && *list != '\0') {
10453 list++;
10454 }
10455 /* strip whitespace from front */
10456 while(isspace(*list)) {
10457 list++;
10458 }
10459 continue;
10460 }
10461
10462 /* end of find ends inside another word or at very end of list? */
10463 list_len = strlen(list);
10464 end_find = find + word_len;
10465 end_list = list + list_len;
10466 if (end_find == end_list || *end_find != ' ') {
10467 list = find;
10468 /* strip word from front */
10469 while(!isspace(*list) && *list != '\0') {
10470 list++;
10471 }
10472 /* strip whitespace from front */
10473 while(isspace(*list)) {
10474 list++;
10475 }
10476 continue;
10477 }
10478
10479 /* terminating conditions satisfied, word at beginning or separated by ' ' */
10480 return 1;
10481 }
10482
10483 return 0;
10484}
10485
10486/*!
10487 * \brief Check if a given word is in a space-delimited list
10488 *
10489 * \param line The line as typed not including the current word being completed
10490 * \param word The word currently being completed
10491 * \param pos The number of completed words in line
10492 * \param state The nth desired completion option
10493 * \param word_list_offset Offset into the line where the list of queues begins. If non-zero, queues in the list will not be offered for further completion.
10494 *
10495 * \return Returns the queue tab-completion for the given word and state
10496*/
10497static char *complete_queue(const char *line, const char *word, int pos, int state, ptrdiff_t word_list_offset)
10498{
10499 struct call_queue *q;
10500 char *ret = NULL;
10501 int which = 0;
10502 int wordlen = strlen(word);
10503 struct ao2_iterator queue_iter;
10504 const char *word_list = NULL;
10505
10506 /* for certain commands, already completed items should be left out of
10507 * the list */
10508 if (word_list_offset && strlen(line) >= word_list_offset) {
10509 word_list = line + word_list_offset;
10510 }
10511
10512 queue_iter = ao2_iterator_init(queues, 0);
10513 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
10514 if (!strncasecmp(word, q->name, wordlen) && ++which > state
10515 && (!word_list_offset || !word_list || !word_in_list(word_list, q->name))) {
10516 ret = ast_strdup(q->name);
10517 queue_t_unref(q, "Done with iterator");
10518 break;
10519 }
10520 queue_t_unref(q, "Done with iterator");
10521 }
10522 ao2_iterator_destroy(&queue_iter);
10523
10524 /* Pretend "rules" is at the end of the queues list in certain
10525 * circumstances since it is an alternate command that should be
10526 * tab-completable for "queue show" */
10527 if (!ret && which == state && !wordlen && !strncmp("queue show", line, 10)) {
10528 ret = ast_strdup("rules");
10529 }
10530
10531 return ret;
10532}
10533
10534static char *complete_queue_show(const char *line, const char *word, int pos, int state)
10535{
10536 if (pos == 2) {
10537 return complete_queue(line, word, pos, state, 0);
10538 }
10539 return NULL;
10540}
10541
10542static char *queue_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
10543{
10544 switch ( cmd ) {
10545 case CLI_INIT:
10546 e->command = "queue show";
10547 e->usage =
10548 "Usage: queue show\n"
10549 " Provides summary information on a specified queue.\n";
10550 return NULL;
10551 case CLI_GENERATE:
10552 return complete_queue_show(a->line, a->word, a->pos, a->n);
10553 }
10554
10555 return __queues_show(NULL, a->fd, a->argc, a->argv);
10556}
10557
10558static int manager_queue_rule_show(struct mansession *s, const struct message *m)
10559{
10560 const char *rule = astman_get_header(m, "Rule");
10561 const char *id = astman_get_header(m, "ActionID");
10562 struct rule_list *rl_iter;
10563 struct penalty_rule *pr_iter;
10564
10565 astman_append(s, "Response: Success\r\n");
10566 if (!ast_strlen_zero(id)) {
10567 astman_append(s, "ActionID: %s\r\n", id);
10568 }
10569
10571 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) {
10572 if (ast_strlen_zero(rule) || !strcasecmp(rule, rl_iter->name)) {
10573 astman_append(s, "RuleList: %s\r\n", rl_iter->name);
10574 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) {
10575 astman_append(s, "Rule: %d,%s%d,%s%d\r\n", pr_iter->time, pr_iter->max_relative && pr_iter->max_value >= 0 ? "+" : "", pr_iter->max_value, pr_iter->min_relative && pr_iter->min_value >= 0 ? "+" : "", pr_iter->min_value );
10576 }
10577 if (!ast_strlen_zero(rule)) {
10578 break;
10579 }
10580 }
10581 }
10583
10584 /*
10585 * Two blank lines instead of one because the Response and
10586 * ActionID headers used to not be present.
10587 */
10588 astman_append(s, "\r\n\r\n");
10589
10590 return RESULT_SUCCESS;
10591}
10592
10593/*! \brief Summary of queue info via the AMI */
10594static int manager_queues_summary(struct mansession *s, const struct message *m)
10595{
10596 time_t now;
10597 int qmemcount = 0;
10598 int qmemavail = 0;
10599 int qchancount = 0;
10600 int qlongestholdtime = 0;
10601 int qsummaries = 0;
10602 const char *id = astman_get_header(m, "ActionID");
10603 const char *queuefilter = astman_get_header(m, "Queue");
10604 char idText[256];
10605 struct call_queue *q;
10606 struct queue_ent *qe;
10607 struct member *mem;
10608 struct ao2_iterator queue_iter;
10609 struct ao2_iterator mem_iter;
10610
10611 if (ast_check_realtime("queues")) {
10612 load_realtime_queues(queuefilter);
10613 }
10614
10615 astman_send_listack(s, m, "Queue summary will follow", "start");
10616 time(&now);
10617 idText[0] = '\0';
10618 if (!ast_strlen_zero(id)) {
10619 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
10620 }
10621 queue_iter = ao2_iterator_init(queues, 0);
10622 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
10623 ao2_lock(q);
10624
10625 /* List queue properties */
10626 if (ast_strlen_zero(queuefilter) || !strcasecmp(q->name, queuefilter)) {
10627 /* Reset the necessary local variables if no queuefilter is set*/
10628 qmemcount = 0;
10629 qmemavail = 0;
10630 qchancount = 0;
10631 qlongestholdtime = 0;
10632
10633 /* List Queue Members */
10634 mem_iter = ao2_iterator_init(q->members, 0);
10635 while ((mem = ao2_iterator_next(&mem_iter))) {
10636 if ((mem->status != AST_DEVICE_UNAVAILABLE) && (mem->status != AST_DEVICE_INVALID)) {
10637 ++qmemcount;
10638 if (member_status_available(mem->status) && !mem->paused) {
10639 ++qmemavail;
10640 }
10641 }
10642 ao2_ref(mem, -1);
10643 }
10644 ao2_iterator_destroy(&mem_iter);
10645 for (qe = q->head; qe; qe = qe->next) {
10646 if ((now - qe->start) > qlongestholdtime) {
10647 qlongestholdtime = now - qe->start;
10648 }
10649 ++qchancount;
10650 }
10651 astman_append(s, "Event: QueueSummary\r\n"
10652 "Queue: %s\r\n"
10653 "LoggedIn: %d\r\n"
10654 "Available: %d\r\n"
10655 "Callers: %d\r\n"
10656 "HoldTime: %d\r\n"
10657 "TalkTime: %d\r\n"
10658 "LongestHoldTime: %d\r\n"
10659 "%s"
10660 "\r\n",
10661 q->name, qmemcount, qmemavail, qchancount, q->holdtime, q->talktime, qlongestholdtime, idText);
10662 ++qsummaries;
10663 }
10664 ao2_unlock(q);
10665 queue_t_unref(q, "Done with iterator");
10666 }
10667 ao2_iterator_destroy(&queue_iter);
10668
10669 astman_send_list_complete_start(s, m, "QueueSummaryComplete", qsummaries);
10671
10672 return RESULT_SUCCESS;
10673}
10674
10675/*! \brief Queue status info via AMI */
10676static int manager_queues_status(struct mansession *s, const struct message *m)
10677{
10678 time_t now;
10679 int pos;
10680 int q_items = 0;
10681 const char *id = astman_get_header(m,"ActionID");
10682 const char *queuefilter = astman_get_header(m,"Queue");
10683 const char *memberfilter = astman_get_header(m,"Member");
10684 char idText[256];
10685 struct call_queue *q;
10686 struct queue_ent *qe;
10687 float sl = 0;
10688 float sl2 = 0;
10689 struct member *mem;
10690 struct ao2_iterator queue_iter;
10691 struct ao2_iterator mem_iter;
10692
10693 if (ast_check_realtime("queues")) {
10694 load_realtime_queues(queuefilter);
10695 }
10696
10697 astman_send_listack(s, m, "Queue status will follow", "start");
10698 time(&now);
10699 idText[0] = '\0';
10700 if (!ast_strlen_zero(id)) {
10701 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
10702 }
10703
10704 queue_iter = ao2_iterator_init(queues, 0);
10705 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
10706 ao2_lock(q);
10707
10708 /* List queue properties */
10709 if (ast_strlen_zero(queuefilter) || !strcasecmp(q->name, queuefilter)) {
10710 sl = ((q->callscompleted > 0) ? 100 * ((float)q->callscompletedinsl / (float)q->callscompleted) : 0);
10711 sl2 = (((q->callscompleted + q->callsabandoned) > 0) ? 100 * (((float)q->callsabandonedinsl + (float)q->callscompletedinsl) / ((float)q->callsabandoned + (float)q->callscompleted)) : 0);
10712
10713 astman_append(s, "Event: QueueParams\r\n"
10714 "Queue: %s\r\n"
10715 "Max: %d\r\n"
10716 "Strategy: %s\r\n"
10717 "Calls: %d\r\n"
10718 "Holdtime: %d\r\n"
10719 "TalkTime: %d\r\n"
10720 "Completed: %d\r\n"
10721 "Abandoned: %d\r\n"
10722 "ServiceLevel: %d\r\n"
10723 "ServicelevelPerf: %2.1f\r\n"
10724 "ServicelevelPerf2: %2.1f\r\n"
10725 "Weight: %d\r\n"
10726 "%s"
10727 "\r\n",
10728 q->name, q->maxlen, int2strat(q->strategy), q->count, q->holdtime, q->talktime, q->callscompleted,
10729 q->callsabandoned, q->servicelevel, sl, sl2, q->weight, idText);
10730 ++q_items;
10731
10732 /* List Queue Members */
10733 mem_iter = ao2_iterator_init(q->members, 0);
10734 while ((mem = ao2_iterator_next(&mem_iter))) {
10735 if (ast_strlen_zero(memberfilter) || !strcmp(mem->interface, memberfilter) || !strcmp(mem->membername, memberfilter)) {
10736 astman_append(s, "Event: QueueMember\r\n"
10737 "Queue: %s\r\n"
10738 "Name: %s\r\n"
10739 "Location: %s\r\n"
10740 "StateInterface: %s\r\n"
10741 "Membership: %s\r\n"
10742 "Penalty: %d\r\n"
10743 "CallsTaken: %d\r\n"
10744 "LastCall: %d\r\n"
10745 "LastPause: %d\r\n"
10746 "LoginTime: %d\r\n"
10747 "InCall: %d\r\n"
10748 "Status: %d\r\n"
10749 "Paused: %d\r\n"
10750 "PausedReason: %s\r\n"
10751 "Wrapuptime: %d\r\n"
10752 "%s"
10753 "\r\n",
10754 q->name, mem->membername, mem->interface, mem->state_interface, mem->dynamic ? "dynamic" : "static",
10755 mem->penalty, mem->calls, (int)mem->lastcall, (int)mem->lastpause, (int)mem->logintime, mem->starttime ? 1 : 0, mem->status,
10756 mem->paused, mem->reason_paused, mem->wrapuptime, idText);
10757 ++q_items;
10758 }
10759 ao2_ref(mem, -1);
10760 }
10761 ao2_iterator_destroy(&mem_iter);
10762
10763 /* List Queue Entries */
10764 pos = 1;
10765 for (qe = q->head; qe; qe = qe->next) {
10766 astman_append(s, "Event: QueueEntry\r\n"
10767 "Queue: %s\r\n"
10768 "Position: %d\r\n"
10769 "Channel: %s\r\n"
10770 "Uniqueid: %s\r\n"
10771 "CallerIDNum: %s\r\n"
10772 "CallerIDName: %s\r\n"
10773 "ConnectedLineNum: %s\r\n"
10774 "ConnectedLineName: %s\r\n"
10775 "Wait: %ld\r\n"
10776 "Priority: %d\r\n"
10777 "%s"
10778 "\r\n",
10779 q->name, pos++, ast_channel_name(qe->chan), ast_channel_uniqueid(qe->chan),
10784 (long) (now - qe->start), qe->prio, idText);
10785 ++q_items;
10786 }
10787 }
10788 ao2_unlock(q);
10789 queue_t_unref(q, "Done with iterator");
10790 }
10791 ao2_iterator_destroy(&queue_iter);
10792
10793 astman_send_list_complete_start(s, m, "QueueStatusComplete", q_items);
10795
10796 return RESULT_SUCCESS;
10797}
10798
10799static int manager_add_queue_member(struct mansession *s, const struct message *m)
10800{
10801 const char *queuename, *interface, *penalty_s, *paused_s, *reason, *membername, *state_interface, *wrapuptime_s;
10802 int paused, penalty, wrapuptime = 0;
10803
10804 queuename = astman_get_header(m, "Queue");
10805 interface = astman_get_header(m, "Interface");
10806 penalty_s = astman_get_header(m, "Penalty");
10807 paused_s = astman_get_header(m, "Paused");
10808 reason = astman_get_header(m, "Reason"); /* Optional */
10809 membername = astman_get_header(m, "MemberName");
10810 state_interface = astman_get_header(m, "StateInterface");
10811 wrapuptime_s = astman_get_header(m, "Wrapuptime");
10812
10813 if (ast_strlen_zero(queuename)) {
10814 astman_send_error(s, m, "'Queue' not specified.");
10815 return 0;
10816 }
10817
10818 if (ast_strlen_zero(interface)) {
10819 astman_send_error(s, m, "'Interface' not specified.");
10820 return 0;
10821 }
10822
10823 if (ast_strlen_zero(penalty_s)) {
10824 penalty = 0;
10825 } else if (sscanf(penalty_s, "%30d", &penalty) != 1 || penalty < 0) {
10826 penalty = 0;
10827 }
10828
10829 if (ast_strlen_zero(wrapuptime_s)) {
10830 wrapuptime = 0;
10831 } else if (sscanf(wrapuptime_s, "%30d", &wrapuptime) != 1 || wrapuptime < 0) {
10832 wrapuptime = 0;
10833 }
10834
10835 if (ast_strlen_zero(paused_s)) {
10836 paused = 0;
10837 } else {
10838 paused = abs(ast_true(paused_s));
10839 }
10840
10841 switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface, reason, wrapuptime)) {
10842 case RES_OKAY:
10843 if (ast_strlen_zero(membername) || !log_membername_as_agent) {
10844 ast_queue_log(queuename, "MANAGER", interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
10845 } else {
10846 ast_queue_log(queuename, "MANAGER", membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
10847 }
10848 astman_send_ack(s, m, "Added interface to queue");
10849 break;
10850 case RES_EXISTS:
10851 astman_send_error(s, m, "Unable to add interface: Already there");
10852 break;
10853 case RES_NOSUCHQUEUE:
10854 astman_send_error(s, m, "Unable to add interface to queue: No such queue");
10855 break;
10856 case RES_OUTOFMEMORY:
10857 astman_send_error(s, m, "Out of memory");
10858 break;
10859 }
10860
10861 return 0;
10862}
10863
10864static int manager_remove_queue_member(struct mansession *s, const struct message *m)
10865{
10866 const char *queuename, *interface;
10867 struct member *mem = NULL;
10868
10869 queuename = astman_get_header(m, "Queue");
10870 interface = astman_get_header(m, "Interface");
10871
10872 if (ast_strlen_zero(queuename) || ast_strlen_zero(interface)) {
10873 astman_send_error(s, m, "Need 'Queue' and 'Interface' parameters.");
10874 return 0;
10875 }
10876
10878 mem = find_member_by_queuename_and_interface(queuename, interface);
10879 }
10880
10881 switch (remove_from_queue(queuename, interface)) {
10882 case RES_OKAY:
10883 if (!mem || ast_strlen_zero(mem->membername)) {
10884 ast_queue_log(queuename, "MANAGER", interface, "REMOVEMEMBER", "%s", "");
10885 } else {
10886 ast_queue_log(queuename, "MANAGER", mem->membername, "REMOVEMEMBER", "%s", "");
10887 }
10888 astman_send_ack(s, m, "Removed interface from queue");
10889 break;
10890 case RES_EXISTS:
10891 astman_send_error(s, m, "Unable to remove interface: Not there");
10892 break;
10893 case RES_NOSUCHQUEUE:
10894 astman_send_error(s, m, "Unable to remove interface from queue: No such queue");
10895 break;
10896 case RES_OUTOFMEMORY:
10897 astman_send_error(s, m, "Out of memory");
10898 break;
10899 case RES_NOT_DYNAMIC:
10900 astman_send_error(s, m, "Member not dynamic");
10901 break;
10902 }
10903
10904 if (mem) {
10905 ao2_ref(mem, -1);
10906 }
10907
10908 return 0;
10909}
10910
10911static int manager_pause_queue_member(struct mansession *s, const struct message *m)
10912{
10913 const char *queuename, *interface, *paused_s, *reason;
10914 int paused;
10915
10916 interface = astman_get_header(m, "Interface");
10917 paused_s = astman_get_header(m, "Paused");
10918 queuename = astman_get_header(m, "Queue"); /* Optional - if not supplied, pause the given Interface in all queues */
10919 reason = astman_get_header(m, "Reason"); /* Optional */
10920
10921 if (ast_strlen_zero(interface) || ast_strlen_zero(paused_s)) {
10922 astman_send_error(s, m, "Need 'Interface' and 'Paused' parameters.");
10923 return 0;
10924 }
10925
10926 paused = abs(ast_true(paused_s));
10927
10928 if (set_member_paused(queuename, interface, reason, paused)) {
10929 astman_send_error(s, m, "Interface not found");
10930 } else {
10931 astman_send_ack(s, m, paused ? "Interface paused successfully" : "Interface unpaused successfully");
10932 }
10933 return 0;
10934}
10935
10936static int manager_queue_log_custom(struct mansession *s, const struct message *m)
10937{
10938 const char *queuename, *event, *message, *interface, *uniqueid;
10939
10940 queuename = astman_get_header(m, "Queue");
10941 uniqueid = astman_get_header(m, "UniqueId");
10942 interface = astman_get_header(m, "Interface");
10943 event = astman_get_header(m, "Event");
10944 message = astman_get_header(m, "Message");
10945
10946 if (ast_strlen_zero(queuename) || ast_strlen_zero(event)) {
10947 astman_send_error(s, m, "Need 'Queue' and 'Event' parameters.");
10948 return 0;
10949 }
10950
10951 ast_queue_log(queuename, S_OR(uniqueid, "NONE"), interface, event, "%s", message);
10952 astman_send_ack(s, m, "Event added successfully");
10953
10954 return 0;
10955}
10956
10957static int manager_queue_reload(struct mansession *s, const struct message *m)
10958{
10959 struct ast_flags mask = {0,};
10960 const char *queuename = NULL;
10961 int header_found = 0;
10962
10963 queuename = astman_get_header(m, "Queue");
10964 if (!strcasecmp(S_OR(astman_get_header(m, "Members"), ""), "yes")) {
10966 header_found = 1;
10967 }
10968 if (!strcasecmp(S_OR(astman_get_header(m, "Rules"), ""), "yes")) {
10970 header_found = 1;
10971 }
10972 if (!strcasecmp(S_OR(astman_get_header(m, "Parameters"), ""), "yes")) {
10974 header_found = 1;
10975 }
10976
10977 if (!header_found) {
10979 }
10980
10981 if (!reload_handler(1, &mask, queuename)) {
10982 astman_send_ack(s, m, "Queue reloaded successfully");
10983 } else {
10984 astman_send_error(s, m, "Error encountered while reloading queue");
10985 }
10986 return 0;
10987}
10988
10989static int manager_queue_reset(struct mansession *s, const struct message *m)
10990{
10991 const char *queuename = NULL;
10992 struct ast_flags mask = {QUEUE_RESET_STATS,};
10993
10994 queuename = astman_get_header(m, "Queue");
10995
10996 if (!reload_handler(1, &mask, queuename)) {
10997 astman_send_ack(s, m, "Queue stats reset successfully");
10998 } else {
10999 astman_send_error(s, m, "Error encountered while resetting queue stats");
11000 }
11001 return 0;
11002}
11003
11004static char *complete_queue_add_member(const char *line, const char *word, int pos, int state)
11005{
11006 /* 0 - queue; 1 - add; 2 - member; 3 - <interface>; 4 - to; 5 - <queue>; 6 - penalty; 7 - <penalty>; 8 - as; 9 - <membername> */
11007 switch (pos) {
11008 case 3: /* Don't attempt to complete name of interface (infinite possibilities) */
11009 return NULL;
11010 case 4: /* only one possible match, "to" */
11011 return state == 0 ? ast_strdup("to") : NULL;
11012 case 5: /* <queue> */
11013 return complete_queue(line, word, pos, state, 0);
11014 case 6: /* only one possible match, "penalty" */
11015 return state == 0 ? ast_strdup("penalty") : NULL;
11016 case 7:
11017 if (0 <= state && state < 100) { /* 0-99 */
11018 char *num;
11019 if ((num = ast_malloc(3))) {
11020 sprintf(num, "%d", state);
11021 }
11022 return num;
11023 } else {
11024 return NULL;
11025 }
11026 case 8: /* only one possible match, "as" */
11027 return state == 0 ? ast_strdup("as") : NULL;
11028 case 9: /* Don't attempt to complete name of member (infinite possibilities) */
11029 return NULL;
11030 default:
11031 return NULL;
11032 }
11033}
11034
11035static int manager_queue_member_ringinuse(struct mansession *s, const struct message *m)
11036{
11037 const char *queuename, *interface, *ringinuse_s;
11038 int ringinuse;
11039
11040 interface = astman_get_header(m, "Interface");
11041 ringinuse_s = astman_get_header(m, "RingInUse");
11042
11043 /* Optional - if not supplied, set the ringinuse value for the given Interface in all queues */
11044 queuename = astman_get_header(m, "Queue");
11045
11046 if (ast_strlen_zero(interface) || ast_strlen_zero(ringinuse_s)) {
11047 astman_send_error(s, m, "Need 'Interface' and 'RingInUse' parameters.");
11048 return 0;
11049 }
11050
11051 if (ast_true(ringinuse_s)) {
11052 ringinuse = 1;
11053 } else if (ast_false(ringinuse_s)) {
11054 ringinuse = 0;
11055 } else {
11056 astman_send_error(s, m, "'RingInUse' parameter must be a truth value (yes/no, on/off, 0/1, etc)");
11057 return 0;
11058 }
11059
11060 if (set_member_value(queuename, interface, MEMBER_RINGINUSE, ringinuse)) {
11061 astman_send_error(s, m, "Invalid interface, queuename, or ringinuse value\n");
11062 } else {
11063 astman_send_ack(s, m, "Interface ringinuse set successfully");
11064 }
11065
11066 return 0;
11067}
11068
11069static int manager_queue_member_penalty(struct mansession *s, const struct message *m)
11070{
11071 const char *queuename, *interface, *penalty_s;
11072 int penalty;
11073
11074 interface = astman_get_header(m, "Interface");
11075 penalty_s = astman_get_header(m, "Penalty");
11076 /* Optional - if not supplied, set the penalty value for the given Interface in all queues */
11077 queuename = astman_get_header(m, "Queue");
11078
11079 if (ast_strlen_zero(interface) || ast_strlen_zero(penalty_s)) {
11080 astman_send_error(s, m, "Need 'Interface' and 'Penalty' parameters.");
11081 return 0;
11082 }
11083
11084 penalty = atoi(penalty_s);
11085
11086 if (set_member_value((char *)queuename, (char *)interface, MEMBER_PENALTY, penalty)) {
11087 astman_send_error(s, m, "Invalid interface, queuename or penalty");
11088 } else {
11089 astman_send_ack(s, m, "Interface penalty set successfully");
11090 }
11091
11092 return 0;
11093}
11094
11095static int manager_change_priority_caller_on_queue(struct mansession *s, const struct message *m)
11096{
11097 const char *queuename, *caller, *priority_s, *immediate_s;
11098 int priority = 0, immediate = 0;
11099
11100 queuename = astman_get_header(m, "Queue");
11101 caller = astman_get_header(m, "Caller");
11102 priority_s = astman_get_header(m, "Priority");
11103 immediate_s = astman_get_header(m, "Immediate");
11104
11105 if (ast_strlen_zero(queuename)) {
11106 astman_send_error(s, m, "'Queue' not specified.");
11107 return 0;
11108 }
11109
11110 if (ast_strlen_zero(caller)) {
11111 astman_send_error(s, m, "'Caller' not specified.");
11112 return 0;
11113 }
11114
11115 if (ast_strlen_zero(priority_s)) {
11116 astman_send_error(s, m, "'Priority' not specified.");
11117 return 0;
11118 } else if (sscanf(priority_s, "%30d", &priority) != 1) {
11119 astman_send_error(s, m, "'Priority' need integer.");
11120 return 0;
11121 }
11122
11123 if (!ast_strlen_zero(immediate_s)) {
11124 immediate = ast_true(immediate_s);
11125 }
11126
11127 switch (change_priority_caller_on_queue(queuename, caller, priority, immediate)) {
11128 case RES_OKAY:
11129 astman_send_ack(s, m, "Priority change for caller on queue");
11130 break;
11131 case RES_NOSUCHQUEUE:
11132 astman_send_error(s, m, "Unable to change priority caller on queue: No such queue");
11133 break;
11134 case RES_NOT_CALLER:
11135 astman_send_error(s, m, "Unable to change priority caller on queue: No such caller");
11136 break;
11137 }
11138
11139 return 0;
11140}
11141
11143{
11144 const char *queuename, *caller, *withdraw_info;
11145
11146 queuename = astman_get_header(m, "Queue");
11147 caller = astman_get_header(m, "Caller");
11148 withdraw_info = astman_get_header(m, "WithdrawInfo");
11149
11150 if (ast_strlen_zero(queuename)) {
11151 astman_send_error(s, m, "'Queue' not specified.");
11152 return 0;
11153 }
11154
11155 if (ast_strlen_zero(caller)) {
11156 astman_send_error(s, m, "'Caller' not specified.");
11157 return 0;
11158 }
11159
11160 switch (request_withdraw_caller_from_queue(queuename, caller, withdraw_info)) {
11161 case RES_OKAY:
11162 astman_send_ack(s, m, "Withdraw requested successfully");
11163 break;
11164 case RES_NOSUCHQUEUE:
11165 astman_send_error(s, m, "Unable to request withdraw from queue: No such queue");
11166 break;
11167 case RES_NOT_CALLER:
11168 astman_send_error(s, m, "Unable to request withdraw from queue: No such caller");
11169 break;
11170 case RES_EXISTS:
11171 astman_send_error(s, m, "Unable to request withdraw from queue: Already requested");
11172 break;
11173 }
11174
11175 return 0;
11176}
11177
11178
11179static char *handle_queue_add_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11180{
11181 const char *queuename, *interface, *membername = NULL, *state_interface = NULL, *reason = NULL;
11182 int penalty, paused = 0;
11183
11184 switch ( cmd ) {
11185 case CLI_INIT:
11186 e->command = "queue add member";
11187 e->usage =
11188 "Usage: queue add member <dial string> to <queue> [penalty <penalty> [as <membername> [state_interface <interface> [paused <reason>]]]]\n"
11189 " Add a dial string (Such as a channel,e.g. SIP/6001) to a queue with optionally: a penalty, membername and a state_interface\n";
11190 return NULL;
11191 case CLI_GENERATE:
11192 return complete_queue_add_member(a->line, a->word, a->pos, a->n);
11193 }
11194
11195 if ((a->argc != 6) && (a->argc != 8) && (a->argc != 10) && (a->argc != 12) && (a->argc != 14)) {
11196 return CLI_SHOWUSAGE;
11197 } else if (strcmp(a->argv[4], "to")) {
11198 return CLI_SHOWUSAGE;
11199 } else if ((a->argc >= 8) && strcmp(a->argv[6], "penalty")) {
11200 return CLI_SHOWUSAGE;
11201 } else if ((a->argc >= 10) && strcmp(a->argv[8], "as")) {
11202 return CLI_SHOWUSAGE;
11203 } else if ((a->argc == 12) && strcmp(a->argv[10], "state_interface")) {
11204 return CLI_SHOWUSAGE;
11205 } else if ((a->argc == 14) && strcmp(a->argv[12], "paused")) {
11206 return CLI_SHOWUSAGE;
11207 }
11208
11209 queuename = a->argv[5];
11210 interface = a->argv[3];
11211 if (a->argc >= 8) {
11212 if (sscanf(a->argv[7], "%30d", &penalty) == 1) {
11213 if (penalty < 0) {
11214 ast_cli(a->fd, "Penalty must be >= 0\n");
11215 penalty = 0;
11216 }
11217 } else {
11218 ast_cli(a->fd, "Penalty must be an integer >= 0\n");
11219 penalty = 0;
11220 }
11221 } else {
11222 penalty = 0;
11223 }
11224
11225 if (a->argc >= 10) {
11226 membername = a->argv[9];
11227 }
11228
11229 if (a->argc >= 12) {
11230 state_interface = a->argv[11];
11231 }
11232
11233 if (a->argc >= 14) {
11234 paused = 1;
11235 reason = a->argv[13];
11236 }
11237
11238 switch (add_to_queue(queuename, interface, membername, penalty, paused, queue_persistent_members, state_interface, reason, 0)) {
11239 case RES_OKAY:
11240 if (ast_strlen_zero(membername) || !log_membername_as_agent) {
11241 ast_queue_log(queuename, "CLI", interface, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
11242 } else {
11243 ast_queue_log(queuename, "CLI", membername, "ADDMEMBER", "%s", paused ? "PAUSED" : "");
11244 }
11245 ast_cli(a->fd, "Added interface '%s' to queue '%s'\n", interface, queuename);
11246 return CLI_SUCCESS;
11247 case RES_EXISTS:
11248 ast_cli(a->fd, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
11249 return CLI_FAILURE;
11250 case RES_NOSUCHQUEUE:
11251 ast_cli(a->fd, "Unable to add interface to queue '%s': No such queue\n", queuename);
11252 return CLI_FAILURE;
11253 case RES_OUTOFMEMORY:
11254 ast_cli(a->fd, "Out of memory\n");
11255 return CLI_FAILURE;
11256 case RES_NOT_DYNAMIC:
11257 ast_cli(a->fd, "Member not dynamic\n");
11258 return CLI_FAILURE;
11259 default:
11260 return CLI_FAILURE;
11261 }
11262}
11263
11264static char *complete_queue_remove_member(const char *line, const char *word, int pos, int state)
11265{
11266 int which = 0;
11267 struct call_queue *q;
11268 struct member *m;
11269 struct ao2_iterator queue_iter;
11270 struct ao2_iterator mem_iter;
11271 int wordlen = strlen(word);
11272
11273 /* 0 - queue; 1 - remove; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */
11274 if (pos > 5 || pos < 3) {
11275 return NULL;
11276 }
11277 if (pos == 4) { /* only one possible match, 'from' */
11278 return (state == 0 ? ast_strdup("from") : NULL);
11279 }
11280
11281 if (pos == 5) { /* No need to duplicate code */
11282 return complete_queue(line, word, pos, state, 0);
11283 }
11284
11285 /* here is the case for 3, <member> */
11286 queue_iter = ao2_iterator_init(queues, 0);
11287 while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
11288 ao2_lock(q);
11289 mem_iter = ao2_iterator_init(q->members, 0);
11290 while ((m = ao2_iterator_next(&mem_iter))) {
11291 if (!strncasecmp(word, m->membername, wordlen) && ++which > state) {
11292 char *tmp;
11293 tmp = ast_strdup(m->interface);
11294 ao2_ref(m, -1);
11295 ao2_iterator_destroy(&mem_iter);
11296 ao2_unlock(q);
11297 queue_t_unref(q, "Done with iterator, returning interface name");
11298 ao2_iterator_destroy(&queue_iter);
11299 return tmp;
11300 }
11301 ao2_ref(m, -1);
11302 }
11303 ao2_iterator_destroy(&mem_iter);
11304 ao2_unlock(q);
11305 queue_t_unref(q, "Done with iterator");
11306 }
11307 ao2_iterator_destroy(&queue_iter);
11308
11309 return NULL;
11310}
11311
11312static char *handle_queue_remove_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11313{
11314 const char *queuename, *interface;
11315 struct member *mem = NULL;
11316 char *res = CLI_FAILURE;
11317
11318 switch (cmd) {
11319 case CLI_INIT:
11320 e->command = "queue remove member";
11321 e->usage =
11322 "Usage: queue remove member <channel> from <queue>\n"
11323 " Remove a specific channel from a queue.\n";
11324 return NULL;
11325 case CLI_GENERATE:
11326 return complete_queue_remove_member(a->line, a->word, a->pos, a->n);
11327 }
11328
11329 if (a->argc != 6) {
11330 return CLI_SHOWUSAGE;
11331 } else if (strcmp(a->argv[4], "from")) {
11332 return CLI_SHOWUSAGE;
11333 }
11334
11335 queuename = a->argv[5];
11336 interface = a->argv[3];
11337
11339 mem = find_member_by_queuename_and_interface(queuename, interface);
11340 }
11341
11342 switch (remove_from_queue(queuename, interface)) {
11343 case RES_OKAY:
11344 if (!mem || ast_strlen_zero(mem->membername)) {
11345 ast_queue_log(queuename, "CLI", interface, "REMOVEMEMBER", "%s", "");
11346 } else {
11347 ast_queue_log(queuename, "CLI", mem->membername, "REMOVEMEMBER", "%s", "");
11348 }
11349 ast_cli(a->fd, "Removed interface %s from queue '%s'\n", interface, queuename);
11350 res = CLI_SUCCESS;
11351 break;
11352 case RES_EXISTS:
11353 ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
11354 break;
11355 case RES_NOSUCHQUEUE:
11356 ast_cli(a->fd, "Unable to remove interface from queue '%s': No such queue\n", queuename);
11357 break;
11358 case RES_OUTOFMEMORY:
11359 ast_cli(a->fd, "Out of memory\n");
11360 break;
11361 case RES_NOT_DYNAMIC:
11362 ast_cli(a->fd, "Unable to remove interface '%s' from queue '%s': Member is not dynamic\n", interface, queuename);
11363 break;
11364 }
11365
11366 if (mem) {
11367 ao2_ref(mem, -1);
11368 }
11369
11370 return res;
11371}
11372
11373
11374
11375static char *handle_queue_change_priority_caller(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11376{
11377 const char *queuename, *caller;
11378 int priority, immediate = 0;
11379 char *res = CLI_FAILURE;
11380
11381 switch (cmd) {
11382 case CLI_INIT:
11383 e->command = "queue priority caller";
11384 e->usage =
11385 "Usage: queue priority caller <channel> on <queue> to <priority> [immediate]\n"
11386 " Change the priority of a channel on a queue, optionally applying the change in relation to existing callers.\n";
11387 return NULL;
11388 case CLI_GENERATE:
11389 return NULL;
11390 }
11391
11392 if (a->argc < 8) {
11393 return CLI_SHOWUSAGE;
11394 } else if (strcmp(a->argv[4], "on")) {
11395 return CLI_SHOWUSAGE;
11396 } else if (strcmp(a->argv[6], "to")) {
11397 return CLI_SHOWUSAGE;
11398 } else if (sscanf(a->argv[7], "%30d", &priority) != 1) {
11399 ast_log (LOG_ERROR, "<priority> parameter must be an integer.\n");
11400 return CLI_SHOWUSAGE;
11401 } else if (a->argc == 9) {
11402 if (strcmp(a->argv[8], "immediate")) {
11403 return CLI_SHOWUSAGE;
11404 }
11405 immediate = 1;
11406 }
11407
11408 caller = a->argv[3];
11409 queuename = a->argv[5];
11410
11411 switch (change_priority_caller_on_queue(queuename, caller, priority, immediate)) {
11412 case RES_OKAY:
11413 res = CLI_SUCCESS;
11414 break;
11415 case RES_NOSUCHQUEUE:
11416 ast_cli(a->fd, "Unable change priority caller %s on queue '%s': No such queue\n", caller, queuename);
11417 break;
11418 case RES_NOT_CALLER:
11419 ast_cli(a->fd, "Unable to change priority caller '%s' on queue '%s': Not there\n", caller, queuename);
11420
11421 break;
11422 }
11423
11424 return res;
11425}
11426
11427
11428
11429static char *complete_queue_pause_member(const char *line, const char *word, int pos, int state)
11430{
11431 /* 0 - queue; 1 - pause; 2 - member; 3 - <interface>; 4 - queue; 5 - <queue>; 6 - reason; 7 - <reason> */
11432 switch (pos) {
11433 case 3: /* Don't attempt to complete name of interface (infinite possibilities) */
11434 return NULL;
11435 case 4: /* only one possible match, "queue" */
11436 return state == 0 ? ast_strdup("queue") : NULL;
11437 case 5: /* <queue> */
11438 return complete_queue(line, word, pos, state, 0);
11439 case 6: /* "reason" */
11440 return state == 0 ? ast_strdup("reason") : NULL;
11441 case 7: /* Can't autocomplete a reason, since it's 100% customizeable */
11442 return NULL;
11443 default:
11444 return NULL;
11445 }
11446}
11447
11448static char *handle_queue_pause_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11449{
11450 const char *queuename, *interface, *reason;
11451 int paused;
11452
11453 switch (cmd) {
11454 case CLI_INIT:
11455 e->command = "queue {pause|unpause} member";
11456 e->usage =
11457 "Usage: queue {pause|unpause} member <member> [queue <queue> [reason <reason>]]\n"
11458 " Pause or unpause a queue member. Not specifying a particular queue\n"
11459 " will pause or unpause a member across all queues to which the member\n"
11460 " belongs.\n";
11461 return NULL;
11462 case CLI_GENERATE:
11463 return complete_queue_pause_member(a->line, a-> word, a->pos, a->n);
11464 }
11465
11466 if (a->argc < 4 || a->argc == 5 || a->argc == 7 || a->argc > 8) {
11467 return CLI_SHOWUSAGE;
11468 } else if (a->argc >= 5 && strcmp(a->argv[4], "queue")) {
11469 return CLI_SHOWUSAGE;
11470 } else if (a->argc == 8 && strcmp(a->argv[6], "reason")) {
11471 return CLI_SHOWUSAGE;
11472 }
11473
11474
11475 interface = a->argv[3];
11476 queuename = a->argc >= 6 ? a->argv[5] : NULL;
11477 reason = a->argc == 8 ? a->argv[7] : NULL;
11478 paused = !strcasecmp(a->argv[1], "pause");
11479
11480 if (set_member_paused(queuename, interface, reason, paused) == RESULT_SUCCESS) {
11481 ast_cli(a->fd, "%spaused interface '%s'", paused ? "" : "un", interface);
11482 if (!ast_strlen_zero(queuename)) {
11483 ast_cli(a->fd, " in queue '%s'", queuename);
11484 }
11485 if (!ast_strlen_zero(reason)) {
11486 ast_cli(a->fd, " for reason '%s'", reason);
11487 }
11488 ast_cli(a->fd, "\n");
11489 return CLI_SUCCESS;
11490 } else {
11491 ast_cli(a->fd, "Unable to %spause interface '%s'", paused ? "" : "un", interface);
11492 if (!ast_strlen_zero(queuename)) {
11493 ast_cli(a->fd, " in queue '%s'", queuename);
11494 }
11495 if (!ast_strlen_zero(reason)) {
11496 ast_cli(a->fd, " for reason '%s'", reason);
11497 }
11498 ast_cli(a->fd, "\n");
11499 return CLI_FAILURE;
11500 }
11501}
11502
11503static char *complete_queue_set_member_value(const char *line, const char *word, int pos, int state)
11504{
11505 /* 0 - queue; 1 - set; 2 - penalty/ringinuse; 3 - <value>; 4 - on; 5 - <member>; 6 - in; 7 - <queue>;*/
11506 switch (pos) {
11507 case 4:
11508 if (state == 0) {
11509 return ast_strdup("on");
11510 } else {
11511 return NULL;
11512 }
11513 case 6:
11514 if (state == 0) {
11515 return ast_strdup("in");
11516 } else {
11517 return NULL;
11518 }
11519 case 7:
11520 return complete_queue(line, word, pos, state, 0);
11521 default:
11522 return NULL;
11523 }
11524}
11525
11526static char *handle_queue_set_member_ringinuse(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11527{
11528 const char *queuename = NULL, *interface;
11529 int ringinuse;
11530
11531 switch (cmd) {
11532 case CLI_INIT:
11533 e->command = "queue set ringinuse";
11534 e->usage =
11535 "Usage: queue set ringinuse <yes/no> on <interface> [in <queue>]\n"
11536 " Set a member's ringinuse in the queue specified. If no queue is specified\n"
11537 " then that interface's penalty is set in all queues to which that interface is a member.\n";
11538 break;
11539 return NULL;
11540 case CLI_GENERATE:
11541 return complete_queue_set_member_value(a->line, a->word, a->pos, a->n);
11542 }
11543
11544 /* Sensible argument counts */
11545 if (a->argc != 6 && a->argc != 8) {
11546 return CLI_SHOWUSAGE;
11547 }
11548
11549 /* Uses proper indicational words */
11550 if (strcmp(a->argv[4], "on") || (a->argc > 6 && strcmp(a->argv[6], "in"))) {
11551 return CLI_SHOWUSAGE;
11552 }
11553
11554 /* Set the queue name if applicable */
11555 if (a->argc == 8) {
11556 queuename = a->argv[7];
11557 }
11558
11559 /* Interface being set */
11560 interface = a->argv[5];
11561
11562 /* Check and set the ringinuse value */
11563 if (ast_true(a->argv[3])) {
11564 ringinuse = 1;
11565 } else if (ast_false(a->argv[3])) {
11566 ringinuse = 0;
11567 } else {
11568 return CLI_SHOWUSAGE;
11569 }
11570
11571 switch (set_member_value(queuename, interface, MEMBER_RINGINUSE, ringinuse)) {
11572 case RESULT_SUCCESS:
11573 ast_cli(a->fd, "Set ringinuse on interface '%s' from queue '%s'\n", interface, queuename);
11574 return CLI_SUCCESS;
11575 case RESULT_FAILURE:
11576 ast_cli(a->fd, "Failed to set ringinuse on interface '%s' from queue '%s'\n", interface, queuename);
11577 return CLI_FAILURE;
11578 default:
11579 return CLI_FAILURE;
11580 }
11581}
11582
11583static char *handle_queue_set_member_penalty(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11584{
11585 const char *queuename = NULL, *interface;
11586 int penalty = 0;
11587
11588 switch (cmd) {
11589 case CLI_INIT:
11590 e->command = "queue set penalty";
11591 e->usage =
11592 "Usage: queue set penalty <penalty> on <interface> [in <queue>]\n"
11593 " Set a member's penalty in the queue specified. If no queue is specified\n"
11594 " then that interface's penalty is set in all queues to which that interface is a member\n";
11595 return NULL;
11596 case CLI_GENERATE:
11597 return complete_queue_set_member_value(a->line, a->word, a->pos, a->n);
11598 }
11599
11600 if (a->argc != 6 && a->argc != 8) {
11601 return CLI_SHOWUSAGE;
11602 } else if (strcmp(a->argv[4], "on") || (a->argc > 6 && strcmp(a->argv[6], "in"))) {
11603 return CLI_SHOWUSAGE;
11604 }
11605
11606 if (a->argc == 8) {
11607 queuename = a->argv[7];
11608 }
11609 interface = a->argv[5];
11610 penalty = atoi(a->argv[3]);
11611
11612 switch (set_member_value(queuename, interface, MEMBER_PENALTY, penalty)) {
11613 case RESULT_SUCCESS:
11614 ast_cli(a->fd, "Set penalty on interface '%s' from queue '%s'\n", interface, queuename);
11615 return CLI_SUCCESS;
11616 case RESULT_FAILURE:
11617 ast_cli(a->fd, "Failed to set penalty on interface '%s' from queue '%s'\n", interface, queuename);
11618 return CLI_FAILURE;
11619 default:
11620 return CLI_FAILURE;
11621 }
11622}
11623
11624static char *complete_queue_rule_show(const char *line, const char *word, int pos, int state)
11625{
11626 int which = 0;
11627 struct rule_list *rl_iter;
11628 int wordlen = strlen(word);
11629 char *ret = NULL;
11630 if (pos != 3) /* Wha? */ {
11631 return NULL;
11632 }
11633
11635 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) {
11636 if (!strncasecmp(word, rl_iter->name, wordlen) && ++which > state) {
11637 ret = ast_strdup(rl_iter->name);
11638 break;
11639 }
11640 }
11642
11643 return ret;
11644}
11645
11646static char *handle_queue_rule_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11647{
11648 const char *rule;
11649 struct rule_list *rl_iter;
11650 struct penalty_rule *pr_iter;
11651 switch (cmd) {
11652 case CLI_INIT:
11653 e->command = "queue show rules";
11654 e->usage =
11655 "Usage: queue show rules [rulename]\n"
11656 " Show the list of rules associated with rulename. If no\n"
11657 " rulename is specified, list all rules defined in queuerules.conf\n";
11658 return NULL;
11659 case CLI_GENERATE:
11660 return complete_queue_rule_show(a->line, a->word, a->pos, a->n);
11661 }
11662
11663 if (a->argc != 3 && a->argc != 4) {
11664 return CLI_SHOWUSAGE;
11665 }
11666
11667 rule = a->argc == 4 ? a->argv[3] : "";
11669 AST_LIST_TRAVERSE(&rule_lists, rl_iter, list) {
11670 if (ast_strlen_zero(rule) || !strcasecmp(rl_iter->name, rule)) {
11671 ast_cli(a->fd, "Rule: %s\n", rl_iter->name);
11672 AST_LIST_TRAVERSE(&rl_iter->rules, pr_iter, list) {
11673 ast_cli(a->fd, "\tAfter %d seconds, adjust QUEUE_MAX_PENALTY %s %d, adjust QUEUE_MIN_PENALTY %s %d and adjust QUEUE_RAISE_PENALTY %s %d\n", pr_iter->time, pr_iter->max_relative ? "by" : "to", pr_iter->max_value, pr_iter->min_relative ? "by" : "to", pr_iter->min_value, pr_iter->raise_relative ? "by" : "to", pr_iter->raise_value);
11674 }
11675 }
11676 }
11678 return CLI_SUCCESS;
11679}
11680
11681static char *handle_queue_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11682{
11683 struct ast_flags mask = {QUEUE_RESET_STATS,};
11684 int i;
11685
11686 switch (cmd) {
11687 case CLI_INIT:
11688 e->command = "queue reset stats";
11689 e->usage =
11690 "Usage: queue reset stats [<queuenames>]\n"
11691 "\n"
11692 "Issuing this command will reset statistics for\n"
11693 "<queuenames>, or for all queues if no queue is\n"
11694 "specified.\n";
11695 return NULL;
11696 case CLI_GENERATE:
11697 if (a->pos >= 3) {
11698 return complete_queue(a->line, a->word, a->pos, a->n, 17);
11699 } else {
11700 return NULL;
11701 }
11702 }
11703
11704 if (a->argc < 3) {
11705 return CLI_SHOWUSAGE;
11706 }
11707
11708 if (a->argc == 3) {
11709 reload_handler(1, &mask, NULL);
11710 return CLI_SUCCESS;
11711 }
11712
11713 for (i = 3; i < a->argc; ++i) {
11714 reload_handler(1, &mask, a->argv[i]);
11715 }
11716
11717 return CLI_SUCCESS;
11718}
11719
11720static char *handle_queue_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11721{
11722 struct ast_flags mask = {0,};
11723 int i;
11724
11725 switch (cmd) {
11726 case CLI_INIT:
11727 e->command = "queue reload {parameters|members|rules|all}";
11728 e->usage =
11729 "Usage: queue reload {parameters|members|rules|all} [<queuenames>]\n"
11730 "Reload queues. If <queuenames> are specified, only reload information pertaining\n"
11731 "to <queuenames>. One of 'parameters,' 'members,' 'rules,' or 'all' must be\n"
11732 "specified in order to know what information to reload. Below is an explanation\n"
11733 "of each of these qualifiers.\n"
11734 "\n"
11735 "\t'members' - reload queue members from queues.conf\n"
11736 "\t'parameters' - reload all queue options except for queue members\n"
11737 "\t'rules' - reload the queuerules.conf file\n"
11738 "\t'all' - reload queue rules, parameters, and members\n"
11739 "\n"
11740 "Note: the 'rules' qualifier here cannot actually be applied to a specific queue.\n"
11741 "Use of the 'rules' qualifier causes queuerules.conf to be reloaded. Even if only\n"
11742 "one queue is specified when using this command, reloading queue rules may cause\n"
11743 "other queues to be affected\n";
11744 return NULL;
11745 case CLI_GENERATE:
11746 if (a->pos >= 3) {
11747 /* find the point at which the list of queue names starts */
11748 const char *command_end = a->line + strlen("queue reload ");
11749 command_end = strchr(command_end, ' ');
11750 if (!command_end) {
11751 command_end = a->line + strlen(a->line);
11752 }
11753 return complete_queue(a->line, a->word, a->pos, a->n, command_end - a->line);
11754 } else {
11755 return NULL;
11756 }
11757 }
11758
11759 if (a->argc < 3)
11760 return CLI_SHOWUSAGE;
11761
11762 if (!strcasecmp(a->argv[2], "rules")) {
11764 } else if (!strcasecmp(a->argv[2], "members")) {
11766 } else if (!strcasecmp(a->argv[2], "parameters")) {
11768 } else if (!strcasecmp(a->argv[2], "all")) {
11770 }
11771
11772 if (a->argc == 3) {
11773 reload_handler(1, &mask, NULL);
11774 return CLI_SUCCESS;
11775 }
11776
11777 for (i = 3; i < a->argc; ++i) {
11778 reload_handler(1, &mask, a->argv[i]);
11779 }
11780
11781 return CLI_SUCCESS;
11782}
11783
11784/*!
11785 * \brief Update Queue with data of an outgoing call
11786*/
11787static int qupd_exec(struct ast_channel *chan, const char *data)
11788{
11789 int oldtalktime;
11790 char *parse;
11791 struct call_queue *q;
11792 struct member *mem;
11793 int newtalktime = 0;
11794
11796 AST_APP_ARG(queuename);
11797 AST_APP_ARG(uniqueid);
11798 AST_APP_ARG(agent);
11800 AST_APP_ARG(talktime);
11801 AST_APP_ARG(params););
11802
11803 if (ast_strlen_zero(data)) {
11804 ast_log(LOG_WARNING, "QueueUpdate requires arguments (queuename,uniqueid,agent,status,talktime,params[totaltime,callednumber])\n");
11805 return -1;
11806 }
11807
11808 parse = ast_strdupa(data);
11809
11811
11812 if (ast_strlen_zero(args.queuename) || ast_strlen_zero(args.uniqueid) || ast_strlen_zero(args.agent) || ast_strlen_zero(args.status)) {
11813 ast_log(LOG_WARNING, "Missing argument to QueueUpdate (queuename,uniqueid,agent,status,talktime,params[totaltime|callednumber])\n");
11814 return -1;
11815 }
11816
11817 if (!ast_strlen_zero(args.talktime)) {
11818 newtalktime = atoi(args.talktime);
11819 }
11820
11821 q = find_load_queue_rt_friendly(args.queuename);
11822 if (!q) {
11823 ast_log(LOG_WARNING, "QueueUpdate could not find requested queue '%s'\n", args.queuename);
11824 return 0;
11825 }
11826
11827 ao2_lock(q);
11828 if (q->members) {
11829 struct ao2_iterator mem_iter = ao2_iterator_init(q->members, 0);
11830 while ((mem = ao2_iterator_next(&mem_iter))) {
11831 if (!strcasecmp(mem->membername, args.agent)) {
11832 if (!strcasecmp(args.status, "ANSWER")) {
11833 oldtalktime = q->talktime;
11834 q->talktime = (((oldtalktime << 2) - oldtalktime) + newtalktime) >> 2;
11835 time(&mem->lastcall);
11836 mem->calls++;
11837 mem->lastqueue = q;
11838 q->callscompleted++;
11839
11840 if (newtalktime <= q->servicelevel) {
11841 q->callscompletedinsl++;
11842 }
11843 } else {
11844
11845 time(&mem->lastcall);
11846 q->callsabandoned++;
11847 }
11848
11849 ast_queue_log(args.queuename, args.uniqueid, args.agent, "OUTCALL", "%s|%s|%s", args.status, args.talktime, args.params);
11850 }
11851
11852 ao2_ref(mem, -1);
11853 }
11854
11855 ao2_iterator_destroy(&mem_iter);
11856 }
11857
11858 ao2_unlock(q);
11859 queue_t_unref(q, "Done with temporary pointer");
11860
11861 return 0;
11862}
11863
11864static struct ast_cli_entry cli_queue[] = {
11865 AST_CLI_DEFINE(queue_show, "Show status of a specified queue"),
11866 AST_CLI_DEFINE(handle_queue_rule_show, "Show the rules defined in queuerules.conf"),
11867 AST_CLI_DEFINE(handle_queue_add_member, "Add a channel to a specified queue"),
11868 AST_CLI_DEFINE(handle_queue_remove_member, "Removes a channel from a specified queue"),
11869 AST_CLI_DEFINE(handle_queue_pause_member, "Pause or unpause a queue member"),
11870 AST_CLI_DEFINE(handle_queue_set_member_penalty, "Set penalty for a channel of a specified queue"),
11871 AST_CLI_DEFINE(handle_queue_set_member_ringinuse, "Set ringinuse for a channel of a specified queue"),
11872 AST_CLI_DEFINE(handle_queue_reload, "Reload queues, members, queue rules, or parameters"),
11873 AST_CLI_DEFINE(handle_queue_reset, "Reset statistics for a queue"),
11874 AST_CLI_DEFINE(handle_queue_change_priority_caller, "Change priority caller on queue"),
11875};
11876
11879
11880static int unload_module(void)
11881{
11884
11886
11887 STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_join_type);
11888 STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_leave_type);
11889 STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_abandon_type);
11890
11891 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_status_type);
11892 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_added_type);
11893 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_removed_type);
11894 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_pause_type);
11895 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_penalty_type);
11896 STASIS_MESSAGE_TYPE_CLEANUP(queue_member_ringinuse_type);
11897
11898 STASIS_MESSAGE_TYPE_CLEANUP(queue_agent_called_type);
11899 STASIS_MESSAGE_TYPE_CLEANUP(queue_agent_connect_type);
11900 STASIS_MESSAGE_TYPE_CLEANUP(queue_agent_complete_type);
11901 STASIS_MESSAGE_TYPE_CLEANUP(queue_agent_dump_type);
11902 STASIS_MESSAGE_TYPE_CLEANUP(queue_agent_ringnoanswer_type);
11903
11905 ast_manager_unregister("QueueStatus");
11906 ast_manager_unregister("QueueRule");
11907 ast_manager_unregister("QueueSummary");
11908 ast_manager_unregister("QueueAdd");
11909 ast_manager_unregister("QueueRemove");
11910 ast_manager_unregister("QueuePause");
11911 ast_manager_unregister("QueueLog");
11912 ast_manager_unregister("QueueUpdate");
11913 ast_manager_unregister("QueuePenalty");
11914 ast_manager_unregister("QueueReload");
11915 ast_manager_unregister("QueueReset");
11916 ast_manager_unregister("QueueMemberRingInUse");
11917 ast_manager_unregister("QueueChangePriorityCaller");
11918 ast_manager_unregister("QueueWithdrawCaller");
11933
11935
11936 ast_unload_realtime("queue_members");
11939
11940 queues = NULL;
11941 return 0;
11942}
11943
11944/*!
11945 * \brief Load the module
11946 *
11947 * Module loading including tests for configuration or dependencies.
11948 * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
11949 * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
11950 * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
11951 * configuration file or other non-critical problem return
11952 * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
11953 */
11954static int load_module(void)
11955{
11956 int err = 0;
11957 struct ast_flags mask = {AST_FLAGS_ALL, };
11958 struct ast_config *member_config;
11959 struct stasis_topic *queue_topic;
11961
11964 if (!queues) {
11966 }
11967
11970 if (!pending_members) {
11971 unload_module();
11973 }
11974
11975 use_weight = 0;
11976
11977 if (reload_handler(0, &mask, NULL)) {
11978 unload_module();
11980 }
11981
11982 ast_realtime_require_field("queue_members", "paused", RQ_INTEGER1, 1, "uniqueid", RQ_UINTEGER2, 5, "reason_paused", RQ_CHAR, 80, SENTINEL);
11983
11984 /*
11985 * This section is used to determine which name for 'ringinuse' to use in realtime members
11986 * Necessary for supporting older setups.
11987 *
11988 * It also checks if 'reason_paused' exists in the realtime backend
11989 */
11990 member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name LIKE", "%", SENTINEL);
11991 if (!member_config) {
11992 realtime_ringinuse_field = "ringinuse";
11993 } else {
11994 const char *config_val;
11995
11996 if ((config_val = ast_variable_retrieve(member_config, NULL, "ringinuse"))) {
11997 ast_log(LOG_NOTICE, "ringinuse field entries found in queue_members table. Using 'ringinuse'\n");
11998 realtime_ringinuse_field = "ringinuse";
11999 } else if ((config_val = ast_variable_retrieve(member_config, NULL, "ignorebusy"))) {
12000 ast_log(LOG_NOTICE, "ignorebusy field found in queue_members table with no ringinuse field. Using 'ignorebusy'\n");
12001 realtime_ringinuse_field = "ignorebusy";
12002 } else {
12003 ast_log(LOG_NOTICE, "No entries were found for ringinuse/ignorebusy in queue_members table. Using 'ringinuse'\n");
12004 realtime_ringinuse_field = "ringinuse";
12005 }
12006
12007 if (ast_variable_retrieve(member_config, NULL, "reason_paused")) {
12009 }
12010 }
12011 ast_config_destroy(member_config);
12012
12015 }
12016
12025 err |= ast_manager_register_xml("QueueStatus", 0, manager_queues_status);
12026 err |= ast_manager_register_xml("QueueSummary", 0, manager_queues_summary);
12033 err |= ast_manager_register_xml("QueueRule", 0, manager_queue_rule_show);
12034 err |= ast_manager_register_xml("QueueReload", 0, manager_queue_reload);
12035 err |= ast_manager_register_xml("QueueReset", 0, manager_queue_reset);
12036 err |= ast_manager_register_xml("QueueChangePriorityCaller", 0, manager_change_priority_caller_on_queue);
12045
12046 /* in the following subscribe call, do I use DEVICE_STATE, or DEVICE_STATE_CHANGE? */
12048 if (!device_state_sub) {
12049 err = -1;
12050 }
12053
12055 queue_topic = ast_queue_topic_all();
12056 if (!manager_topic || !queue_topic) {
12057 unload_module();
12059 }
12061 if (!topic_forwarder) {
12062 unload_module();
12064 }
12065
12068 unload_module();
12070 }
12072 if (!agent_router) {
12073 unload_module();
12075 }
12079 NULL);
12083 NULL);
12084
12085 err |= STASIS_MESSAGE_TYPE_INIT(queue_caller_join_type);
12086 err |= STASIS_MESSAGE_TYPE_INIT(queue_caller_leave_type);
12087 err |= STASIS_MESSAGE_TYPE_INIT(queue_caller_abandon_type);
12088
12089 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_status_type);
12090 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_added_type);
12091 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_removed_type);
12092 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_pause_type);
12093 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_penalty_type);
12094 err |= STASIS_MESSAGE_TYPE_INIT(queue_member_ringinuse_type);
12095
12096 err |= STASIS_MESSAGE_TYPE_INIT(queue_agent_called_type);
12097 err |= STASIS_MESSAGE_TYPE_INIT(queue_agent_connect_type);
12098 err |= STASIS_MESSAGE_TYPE_INIT(queue_agent_complete_type);
12099 err |= STASIS_MESSAGE_TYPE_INIT(queue_agent_dump_type);
12100 err |= STASIS_MESSAGE_TYPE_INIT(queue_agent_ringnoanswer_type);
12101
12102 if (err) {
12103 unload_module();
12105 }
12107}
12108
12109static int reload(void)
12110{
12111 struct ast_flags mask = {AST_FLAGS_ALL & ~QUEUE_RESET_STATS,};
12112 ast_unload_realtime("queue_members");
12113 reload_handler(1, &mask, NULL);
12114 return 0;
12115}
12116
12117/*!
12118 * \brief Find a member by looking up queuename and interface.
12119 * \return member or NULL if member not found.
12120 */
12121static struct member *find_member_by_queuename_and_interface(const char *queuename, const char *interface)
12122{
12123 struct member *mem = NULL;
12124 struct call_queue *q;
12125
12126 if ((q = find_load_queue_rt_friendly(queuename))) {
12127 ao2_lock(q);
12128 mem = ao2_find(q->members, interface, OBJ_KEY);
12129 ao2_unlock(q);
12130 queue_t_unref(q, "Expiring temporary reference.");
12131 }
12132 return mem;
12133}
12134
12136 .support_level = AST_MODULE_SUPPORT_CORE,
12137 .load = load_module,
12138 .unload = unload_module,
12139 .reload = reload,
12140 .load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
Generic Advice of Charge encode and decode routines.
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition aoc.c:322
enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
get the message type, AOC-D, AOC-E, or AOC Request
Definition aoc.c:901
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
Definition aoc.c:458
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition aoc.c:316
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition aoc.c:659
@ AST_AOC_S
Definition aoc.h:64
char digit
jack_status_t status
Definition app_jack.c:149
const char * str
Definition app_jack.c:150
static struct ast_custom_function queuevar_function
Definition app_queue.c:9617
static void handle_bridge_enter(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6531
static struct member * create_queue_member(const char *interface, const char *membername, int penalty, int paused, const char *state_interface, int ringinuse, int wrapuptime)
allocate space for new queue member and set fields based on parameters passed
Definition app_queue.c:3005
static void member_remove_from_queue(struct call_queue *queue, struct member *mem)
Definition app_queue.c:3717
static int is_longest_waiting_caller(struct queue_ent *caller, struct member *member)
Definition app_queue.c:4731
static void load_realtime_queues(const char *queuename)
Definition app_queue.c:4111
static struct member * interface_exists(struct call_queue *q, const char *interface)
Definition app_queue.c:7621
static int is_our_turn(struct queue_ent *qe)
Check if we should start attempting to call queue members.
Definition app_queue.c:5900
static void record_abandoned(struct queue_ent *qe)
Record that a caller gave up on waiting in queue.
Definition app_queue.c:5234
static int queue_function_mem_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Get number either busy / free / ready or total members of a specific queue.
Definition app_queue.c:9219
static char * queue_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int get_wrapuptime(struct call_queue *q, struct member *member)
Return wrapuptime.
Definition app_queue.c:2126
static void rt_handle_member_record(struct call_queue *q, char *category, struct ast_config *member_config)
Find rt member record to update otherwise create one.
Definition app_queue.c:3733
static int context_included(const char *parent, const char *child)
Returns if one context includes another context.
Definition app_queue.c:2917
static void set_queue_variables(struct call_queue *q, struct ast_channel *chan)
Set variables of queue.
Definition app_queue.c:2198
static int manager_queue_reset(struct mansession *s, const struct message *m)
static struct ast_manager_event_blob * queue_member_ringinuse_to_ami(struct stasis_message *message)
Definition app_queue.c:2334
static struct ast_manager_event_blob * queue_member_penalty_to_ami(struct stasis_message *message)
Definition app_queue.c:2329
member_properties
Definition app_queue.c:1899
@ MEMBER_RINGINUSE
Definition app_queue.c:1901
@ MEMBER_PENALTY
Definition app_queue.c:1900
#define RES_NOT_CALLER
Definition app_queue.c:1697
static int setup_stasis_subs(struct queue_ent *qe, struct ast_channel *peer, struct member *mem, time_t holdstart, time_t starttime, int callcompletedinsl)
Definition app_queue.c:6936
#define ANNOUNCEPOSITION_MORE_THAN
Definition app_queue.c:1923
static int pending_members_cmp(void *obj, void *arg, int flags)
Definition app_queue.c:2676
static void queue_reset_global_params(void)
Definition app_queue.c:9729
static int log_caller_id_name
queues.conf [general] option
Definition app_queue.c:1747
static char * complete_queue_rule_show(const char *line, const char *word, int pos, int state)
static void dump_queue_members(struct call_queue *pm_queue)
Dump all members in a specific queue to the database.
Definition app_queue.c:7648
#define QUEUE_UNPAUSED_DEVSTATE
Definition app_queue.c:3692
static struct ast_custom_function queuemembercount_function
Definition app_queue.c:9622
static struct ast_custom_function queuewaitingcount_function
Definition app_queue.c:9633
static int play_file(struct ast_channel *chan, const char *filename)
Definition app_queue.c:4298
static int queue_persistent_members
queues.conf [general] option
Definition app_queue.c:1717
static int montype_default
queues.conf [general] option
Definition app_queue.c:1726
static int mark_member_dead(void *obj, void *arg, int flags)
Definition app_queue.c:9916
static char * app_pqm
Definition app_queue.c:1705
static struct ast_custom_function queuememberlist_function
Definition app_queue.c:9638
static struct ast_manager_event_blob * queue_channel_to_ami(const char *type, struct stasis_message *message)
Definition app_queue.c:2250
static void set_queue_member_ringinuse(struct call_queue *q, struct member *mem, int ringinuse)
Definition app_queue.c:8116
static char * realtime_ringinuse_field
name of the ringinuse field in the realtime database
Definition app_queue.c:1753
static void queue_bridge_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6678
static int remove_from_queue(const char *queuename, const char *interface)
Remove member from queue.
Definition app_queue.c:7703
static int manager_add_queue_member(struct mansession *s, const struct message *m)
#define MAX_PERIODIC_ANNOUNCEMENTS
Definition app_queue.c:1683
static void parse_empty_options(const char *value, enum empty_conditions *empty, int joinempty)
Definition app_queue.c:3444
static int aqm_exec(struct ast_channel *chan, const char *data)
AddQueueMember application.
Definition app_queue.c:8522
static void set_queue_result(struct ast_channel *chan, enum queue_result res)
sets the QUEUESTATUS channel variable
Definition app_queue.c:2045
static struct ast_manager_event_blob * queue_member_pause_to_ami(struct stasis_message *message)
Definition app_queue.c:2324
static void leave_queue(struct queue_ent *qe)
Caller leaving queue.
Definition app_queue.c:4527
#define MAX_QUEUE_BUCKETS
Definition app_queue.c:1690
static int reload_handler(int reload, struct ast_flags *mask, const char *queuename)
The command center for all reload operations.
static int queue_function_exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Check if a given queue exists.
Definition app_queue.c:9177
static int queue_function_memberpenalty_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Dialplan function QUEUE_MEMBER_PENALTY() Gets the members penalty.
Definition app_queue.c:9544
static char * complete_queue_pause_member(const char *line, const char *word, int pos, int state)
static void do_hang(struct callattempt *o)
common hangup actions
Definition app_queue.c:4782
static int set_member_value(const char *queuename, const char *interface, int property, int value)
Definition app_queue.c:8168
static void reload_single_member(const char *memberdata, struct call_queue *q)
reload information pertaining to a single member
Definition app_queue.c:9784
static struct ast_manager_event_blob * queue_agent_ringnoanswer_to_ami(struct stasis_message *message)
Definition app_queue.c:2419
static void send_agent_complete(const char *queuename, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const struct member *member, time_t holdstart, time_t callstart, enum agent_complete_reason rsn)
Send out AMI message with member call completion status information.
Definition app_queue.c:6284
static int reload_queues(int reload, struct ast_flags *mask, const char *queuename)
reload the queues.conf file
static int say_periodic_announcement(struct queue_ent *qe, int ringing)
Playback announcement to queued members if period has elapsed.
Definition app_queue.c:5173
static void reload_single_queue(struct ast_config *cfg, struct ast_flags *mask, const char *queuename)
Reload information pertaining to a particular queue.
Definition app_queue.c:9947
static void setup_mixmonitor(struct queue_ent *qe, const char *filename)
Definition app_queue.c:7068
static struct ast_manager_event_blob * queue_member_removed_to_ami(struct stasis_message *message)
Definition app_queue.c:2319
#define DEFAULT_RETRY
Definition app_queue.c:1680
static int upqm_exec(struct ast_channel *chan, const char *data)
UnpauseQueueMember application.
Definition app_queue.c:8415
static void clear_queue(struct call_queue *q)
Definition app_queue.c:3191
static void handle_attended_transfer(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Handle an attended transfer event.
Definition app_queue.c:6623
static void recalc_holdtime(struct queue_ent *qe, int newholdtime)
Definition app_queue.c:4504
#define RES_NOT_DYNAMIC
Definition app_queue.c:1696
static int compare_weight(struct call_queue *rq, struct member *member)
Definition app_queue.c:4697
static char * handle_queue_pause_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int set_member_ringinuse_help_members(struct call_queue *q, const char *interface, int ringinuse)
Definition app_queue.c:8129
static void queue_agent_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6315
queue_timeout_priority
Definition app_queue.c:1785
@ TIMEOUT_PRIORITY_CONF
Definition app_queue.c:1787
@ TIMEOUT_PRIORITY_APP
Definition app_queue.c:1786
static int queue_function_queuememberlist(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Dialplan function QUEUE_MEMBER_LIST() Get list of members in a specific queue.
Definition app_queue.c:9496
static char * app_ql
Definition app_queue.c:1709
static void queue_set_global_params(struct ast_config *cfg)
Definition app_queue.c:9742
static void reload_queue_members(void)
Reload dynamic queue members persisted into the astdb.
Definition app_queue.c:8268
static int rqm_exec(struct ast_channel *chan, const char *data)
RemoveQueueMember application.
Definition app_queue.c:8451
static int valid_exit(struct queue_ent *qe, char digit)
Check for valid exit from queue via goto.
Definition app_queue.c:4327
aqm_flags
Definition app_queue.c:1617
@ AQMFLAG_REASON
Definition app_queue.c:1619
@ AQMFLAG_PAUSED
Definition app_queue.c:1618
static int is_member_available(struct call_queue *q, struct member *mem)
Definition app_queue.c:2746
#define QUEUE_PAUSED_DEVSTATE
Definition app_queue.c:3691
#define ANNOUNCEPOSITION_NO
Definition app_queue.c:1922
static char * handle_queue_set_member_penalty(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void handle_masquerade(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6877
static int wait_our_turn(struct queue_ent *qe, int ringing, enum queue_result *reason)
The waiting areas for callers who are not actively calling members.
Definition app_queue.c:6039
static void print_queue(struct mansession *s, int fd, struct call_queue *q)
Print a single queue to AMI or the CLI.
char * text
Definition app_queue.c:1772
#define MAX_CALL_ATTEMPT_BUCKETS
Definition app_queue.c:2654
static char * app_rqm
Definition app_queue.c:1703
static void copy_rules(struct queue_ent *qe, const char *rulename)
Copy rule from global list into specified queue.
Definition app_queue.c:8650
static int manager_queue_rule_show(struct mansession *s, const struct message *m)
static const struct strategy strategies[]
static int request_withdraw_caller_from_queue(const char *queuename, const char *caller, const char *withdraw_info)
Request to withdraw a caller from a queue.
Definition app_queue.c:7885
static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
Definition app_queue.c:8020
static int change_priority_caller_on_queue(const char *queuename, const char *caller, int priority, int immediate)
Change priority caller into a queue.
Definition app_queue.c:7809
static struct ao2_container * queues
Definition app_queue.c:2036
static int negative_penalty_invalid
queues.conf [general] option
Definition app_queue.c:1738
#define AST_MAX_WATCHERS
Definition app_queue.c:5346
static int load_realtime_rules(void)
Load queue rules from realtime.
Definition app_queue.c:3332
static void queue_rules_reset_global_params(void)
Definition app_queue.c:9650
static int update_queue(struct call_queue *q, struct member *member, int callcompletedinsl, time_t starttime)
update the queue status
Definition app_queue.c:6127
static void escape_and_substitute(struct ast_channel *chan, const char *input, char *output, size_t size)
Definition app_queue.c:7037
#define RES_OUTOFMEMORY
Definition app_queue.c:1694
static int member_hash_fn(const void *obj, const int flags)
Definition app_queue.c:3060
static int member_cmp_fn(void *obj1, void *obj2, int flags)
Definition app_queue.c:3076
#define queues_t_unlink(c, q, tag)
Definition app_queue.c:2195
#define DEFAULT_MIN_ANNOUNCE_FREQUENCY
The minimum number of seconds between position announcements.
Definition app_queue.c:1688
static void hangupcalls(struct queue_ent *qe, struct callattempt *outgoing, struct ast_channel *exception, int cancel_answered_elsewhere)
Hang up a list of outgoing calls.
Definition app_queue.c:4624
static void queue_stasis_data_destructor(void *obj)
Definition app_queue.c:6414
static struct ast_manager_event_blob * queue_member_added_to_ami(struct stasis_message *message)
Definition app_queue.c:2314
static struct ast_manager_event_blob * queue_agent_dump_to_ami(struct stasis_message *message)
Definition app_queue.c:2414
static int extensionstate2devicestate(int state)
Helper function which converts from extension state to device state values.
Definition app_queue.c:2868
#define queues_t_link(c, q, tag)
Definition app_queue.c:2194
static int extension_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
Definition app_queue.c:2946
static int manager_queue_reload(struct mansession *s, const struct message *m)
static int get_member_penalty(char *queuename, char *interface)
Gets members penalty.
Definition app_queue.c:8237
static int realtime_rules
queuerules.conf [general] option
Definition app_queue.c:1732
static void handle_local_optimization_begin(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6697
static int pqm_exec(struct ast_channel *chan, const char *data)
PauseQueueMember application.
Definition app_queue.c:8379
static char * complete_queue(const char *line, const char *word, int pos, int state, ptrdiff_t word_list_offset)
Check if a given word is in a space-delimited list.
static int get_member_status(struct call_queue *q, int max_penalty, int min_penalty, int raise_penalty, enum empty_conditions conditions, int devstate, int raise_respect_min)
Check if members are available.
Definition app_queue.c:2557
static int calc_metric(struct call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct callattempt *tmp)
Calculate the metric of each member in the outgoing callattempts.
Definition app_queue.c:6199
static char * handle_queue_reset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int qupd_exec(struct ast_channel *chan, const char *data)
Update Queue with data of an outgoing call.
static char * complete_queue_show(const char *line, const char *word, int pos, int state)
static char * handle_queue_set_member_ringinuse(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int queue_function_var(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
create interface var with all queue details.
Definition app_queue.c:9133
static int reload_queue_rules(int reload)
Reload the rules defined in queuerules.conf.
Definition app_queue.c:9670
static char * complete_queue_add_member(const char *line, const char *word, int pos, int state)
static char * handle_queue_change_priority_caller(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_queue_rule_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int manager_queue_member_ringinuse(struct mansession *s, const struct message *m)
static char * complete_queue_set_member_value(const char *line, const char *word, int pos, int state)
static int can_ring_entry(struct queue_ent *qe, struct callattempt *call)
Definition app_queue.c:4812
static const char * int2strat(int strategy)
Definition app_queue.c:2057
#define RES_NOSUCHQUEUE
Definition app_queue.c:1695
static void free_members(struct call_queue *q, int all)
Iterate through queue's member list and delete them.
Definition app_queue.c:3851
static int publish_queue_member_pause(struct call_queue *q, struct member *member)
Definition app_queue.c:7924
static void callattempt_free(struct callattempt *doomed)
Definition app_queue.c:4602
static int store_next_lin(struct queue_ent *qe, struct callattempt *outgoing)
Search for best metric and add to Linear queue.
Definition app_queue.c:5149
#define queue_t_unref(q, tag)
Definition app_queue.c:2193
static struct callattempt * wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed)
Wait for a member to answer the call.
Definition app_queue.c:5360
static void update_status(struct call_queue *q, struct member *m, const int status)
set a member's status based on device state of that member's state_interface.
Definition app_queue.c:2715
static char * app_qupd
Definition app_queue.c:1711
#define queue_unref(q)
Definition app_queue.c:2191
#define ANNOUNCEHOLDTIME_ALWAYS
Definition app_queue.c:1905
static const struct ast_app_option queue_exec_options[128]
Definition app_queue.c:1614
static void queue_publish_multi_channel_blob(struct ast_channel *caller, struct ast_channel *agent, struct stasis_message_type *type, struct ast_json *blob)
Definition app_queue.c:2475
static int shared_lastcall
queues.conf [general] option
Definition app_queue.c:1729
static int manager_queue_member_penalty(struct mansession *s, const struct message *m)
#define queue_t_ref(q, tag)
Definition app_queue.c:2192
static char * __queues_show(struct mansession *s, int fd, int argc, const char *const *argv)
Show queue(s) status and statistics.
static void queue_set_param(struct call_queue *q, const char *param, const char *val, int linenum, int failunknown)
Configure a queue parameter.
Definition app_queue.c:3487
#define ANNOUNCEPOSITION_LIMIT
Definition app_queue.c:1924
static char * app_upqm
Definition app_queue.c:1707
static int clear_stats(const char *queuename)
Facilitates resetting statistics for a queue.
static struct ast_custom_function queuememberpenalty_function
Definition app_queue.c:9643
static void set_queue_member_pause(struct call_queue *q, struct member *mem, const char *reason, int paused)
Definition app_queue.c:7948
static int queue_cmp_cb(void *obj, void *arg, int flags)
Definition app_queue.c:2113
queue_result
Definition app_queue.c:1758
@ QUEUE_FULL
Definition app_queue.c:1765
@ QUEUE_UNKNOWN
Definition app_queue.c:1759
@ QUEUE_WITHDRAW
Definition app_queue.c:1767
@ QUEUE_CONTINUE
Definition app_queue.c:1766
@ QUEUE_LEAVEEMPTY
Definition app_queue.c:1762
@ QUEUE_LEAVEUNAVAIL
Definition app_queue.c:1764
@ QUEUE_JOINUNAVAIL
Definition app_queue.c:1763
@ QUEUE_JOINEMPTY
Definition app_queue.c:1761
@ QUEUE_TIMEOUT
Definition app_queue.c:1760
static int manager_request_withdraw_caller_from_queue(struct mansession *s, const struct message *m)
static char * app
Definition app_queue.c:1699
static int log_unpause_on_reason_change
queues.conf [general] option
Definition app_queue.c:1750
static int set_member_value_help_members(struct call_queue *q, const char *interface, int property, int value)
Definition app_queue.c:8145
static int queue_hash_cb(const void *obj, const int flags)
Definition app_queue.c:2106
static struct call_queue * find_queue_by_name_rt(const char *queuename, struct ast_variable *queue_vars, struct ast_config *member_config)
Reload a single queue via realtime.
Definition app_queue.c:3906
static const char *const pm_family
Persistent Members astdb family.
Definition app_queue.c:1714
#define queue_ref(q)
Definition app_queue.c:2190
static int log_membername_as_agent
queues.conf [general] option
Definition app_queue.c:1741
static void update_qe_rule(struct queue_ent *qe)
update rules for queues
Definition app_queue.c:5949
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
Definition app_queue.c:5330
static struct ast_manager_event_blob * queue_agent_called_to_ami(struct stasis_message *message)
Definition app_queue.c:2399
static int queue_exec(struct ast_channel *chan, const char *data)
The starting point for all queue calls.
Definition app_queue.c:8693
static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason, int position)
Definition app_queue.c:4214
static char * handle_queue_remove_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void rna(int rnatime, struct queue_ent *qe, struct ast_channel *peer, char *interface, char *membername, int autopause)
RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer.
Definition app_queue.c:5265
static const struct ast_app_option aqm_opts[128]
Definition app_queue.c:1630
static void destroy_queue_member_cb(void *obj)
Definition app_queue.c:2995
static void init_queue(struct call_queue *q)
Initialize Queue default values.
Definition app_queue.c:3089
static struct ao2_container * pending_members
Definition app_queue.c:2653
static struct ast_manager_event_blob * queue_multi_channel_to_ami(const char *type, struct stasis_message *message)
Definition app_queue.c:2358
static struct member * find_member_by_queuename_and_interface(const char *queuename, const char *interface)
Find a member by looking up queuename and interface.
static int force_longest_waiting_caller
queues.conf [general] option
Definition app_queue.c:1744
#define RES_OKAY
Definition app_queue.c:1692
static struct ast_manager_event_blob * queue_member_status_to_ami(struct stasis_message *message)
Definition app_queue.c:2309
static int kill_dead_members(void *obj, void *arg, int flags)
Definition app_queue.c:9925
#define DEFAULT_TIMEOUT
Definition app_queue.c:1681
static void remove_stasis_subscriptions(struct queue_stasis_data *queue_data)
Definition app_queue.c:6431
static int queue_function_queuewaitingcount(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Dialplan function QUEUE_WAITING_COUNT() Get number callers waiting in a specific queue.
Definition app_queue.c:9459
static int pending_members_hash(const void *obj, const int flags)
Definition app_queue.c:2656
static int autofill_default
queues.conf [general] option
Definition app_queue.c:1723
static int manager_pause_queue_member(struct mansession *s, const struct message *m)
static void insert_entry(struct call_queue *q, struct queue_ent *prev, struct queue_ent *new, int *pos)
Insert the 'new' entry after the 'prev' entry of queue 'q'.
Definition app_queue.c:2224
#define ANNOUNCEHOLDTIME_ONCE
Definition app_queue.c:1906
static struct ast_manager_event_blob * queue_caller_join_to_ami(struct stasis_message *message)
Definition app_queue.c:2269
static int queue_delme_members_decrement_followers(void *obj, void *arg, int flag)
Definition app_queue.c:2159
static int insert_penaltychange(const char *list_name, const char *content, const int linenum)
Change queue penalty by adding rule.
Definition app_queue.c:3223
static char * handle_queue_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int num_available_members(struct call_queue *q)
Get the number of members available to accept a call.
Definition app_queue.c:4664
static int ql_exec(struct ast_channel *chan, const char *data)
QueueLog application.
Definition app_queue.c:8616
static int manager_remove_queue_member(struct mansession *s, const struct message *m)
static int update_realtime_member_field(struct member *mem, const char *queue_name, const char *field, const char *value)
Definition app_queue.c:4139
static int store_next_rr(struct queue_ent *qe, struct callattempt *outgoing)
Search for best metric and add to Round Robbin queue.
Definition app_queue.c:5125
static struct stasis_message_router * agent_router
static void queue_member_follower_removal(struct call_queue *queue, struct member *mem)
Definition app_queue.c:2177
static struct member * get_interface_helper(struct call_queue *q, const char *interface)
Definition app_queue.c:9196
static int mark_unfound(void *obj, void *arg, int flags)
queue_reload_mask
Definition app_queue.c:1649
@ QUEUE_RELOAD_RULES
Definition app_queue.c:1652
@ QUEUE_RELOAD_MEMBER
Definition app_queue.c:1651
@ QUEUE_RESET_STATS
Definition app_queue.c:1653
@ QUEUE_RELOAD_PARAMETERS
Definition app_queue.c:1650
static void device_state_cb(void *unused, struct stasis_subscription *sub, struct stasis_message *msg)
set a member's status based on device state of that member's interface
Definition app_queue.c:2781
static int load_module(void)
Load the module.
static void member_add_to_queue(struct call_queue *queue, struct member *mem)
Definition app_queue.c:3701
#define RECHECK
Definition app_queue.c:1682
static int ring_entry(struct queue_ent *qe, struct callattempt *tmp, int *busies)
Part 2 of ring_one.
Definition app_queue.c:4908
static void pending_members_remove(struct member *mem)
Definition app_queue.c:2704
static void end_bridge_callback(void *data)
Definition app_queue.c:6997
enum queue_result id
Definition app_queue.c:1771
static struct stasis_subscription * device_state_sub
Subscription to device state change messages.
Definition app_queue.c:1735
static int manager_queues_summary(struct mansession *s, const struct message *m)
Summary of queue info via the AMI.
static struct call_queue * alloc_queue(const char *queuename)
Definition app_queue.c:3882
static struct callattempt * find_best(struct callattempt *outgoing)
find the entry with the best metric, or NULL
Definition app_queue.c:5040
static int get_queue_member_status(struct member *cur)
Return the current state of a member.
Definition app_queue.c:2990
static int unload_module(void)
static int reload(void)
#define QUEUE_UNKNOWN_PAUSED_DEVSTATE
Definition app_queue.c:3693
static void publish_dial_end_event(struct ast_channel *in, struct callattempt *outgoing, struct ast_channel *exception, const char *status)
Definition app_queue.c:4612
static int manager_queues_status(struct mansession *s, const struct message *m)
Queue status info via AMI.
static void handle_local_optimization_end(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6756
static int say_position(struct queue_ent *qe, int ringing)
Definition app_queue.c:4362
static int realtime_reason_paused
does realtime backend support reason_paused
Definition app_queue.c:1756
static struct queue_stasis_data * queue_stasis_data_alloc(struct queue_ent *qe, struct ast_channel *peer, struct member *mem, time_t holdstart, time_t starttime, int callcompletedinsl)
Definition app_queue.c:6446
static void update_realtime_members(struct call_queue *q)
Definition app_queue.c:4155
static int queue_function_memberpenalty_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Dialplan function QUEUE_MEMBER_PENALTY() Sets the members penalty.
Definition app_queue.c:9576
static void queue_publish_multi_channel_snapshot_blob(struct stasis_topic *topic, struct ast_channel_snapshot *caller_snapshot, struct ast_channel_snapshot *agent_snapshot, struct stasis_message_type *type, struct ast_json *blob)
Definition app_queue.c:2440
static int add_to_queue(const char *queuename, const char *interface, const char *membername, int penalty, int paused, int dump, const char *state_interface, const char *reason_paused, int wrapuptime)
Add member to queue.
Definition app_queue.c:7756
static struct ast_manager_event_blob * queue_agent_connect_to_ami(struct stasis_message *message)
Definition app_queue.c:2404
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition app_queue.c:6990
empty_conditions
Definition app_queue.c:1888
@ QUEUE_EMPTY_INVALID
Definition app_queue.c:1894
@ QUEUE_EMPTY_UNKNOWN
Definition app_queue.c:1895
@ QUEUE_EMPTY_PENALTY
Definition app_queue.c:1889
@ QUEUE_EMPTY_RINGING
Definition app_queue.c:1892
@ QUEUE_EMPTY_INUSE
Definition app_queue.c:1891
@ QUEUE_EMPTY_UNAVAILABLE
Definition app_queue.c:1893
@ QUEUE_EMPTY_WRAPUP
Definition app_queue.c:1896
@ QUEUE_EMPTY_PAUSED
Definition app_queue.c:1890
static struct ast_json * queue_member_blob_create(struct call_queue *q, struct member *mem)
Definition app_queue.c:2530
static void queue_channel_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6911
static int use_weight
Records that one or more queues use weight.
Definition app_queue.c:1720
#define ANNOUNCEPOSITION_YES
Definition app_queue.c:1921
static int wait_a_bit(struct queue_ent *qe)
Definition app_queue.c:7608
static char * app_aqm
Definition app_queue.c:1701
static void destroy_queue(void *obj)
Free queue's member list then its string fields.
Definition app_queue.c:3867
static int kill_if_unfound(void *obj, void *arg, int flags)
static void handle_hangup(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Definition app_queue.c:6820
static void do_print(struct mansession *s, int fd, const char *str)
direct output to manager or cli with proper terminator
static char * complete_queue_remove_member(const char *line, const char *word, int pos, int state)
static char * handle_queue_add_member(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define RES_EXISTS
Definition app_queue.c:1693
static int queue_function_mem_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Dialplan function QUEUE_MEMBER() Sets the members penalty / paused / ringinuse.
Definition app_queue.c:9321
static void queue_rules_set_global_params(struct ast_config *cfg)
Definition app_queue.c:9656
static int member_status_available(int status)
Definition app_queue.c:4798
static int queue_member_decrement_followers(void *obj, void *arg, int flag)
Definition app_queue.c:2140
static struct ast_cli_entry cli_queue[]
@ OPT_ARG_CALLEE_GO_ON
Definition app_queue.c:1583
@ OPT_ARG_PREDIAL_CALLEE
Definition app_queue.c:1584
@ OPT_ARG_MUSICONHOLD_CLASS
Definition app_queue.c:1586
@ OPT_ARG_PREDIAL_CALLER
Definition app_queue.c:1585
@ OPT_ARG_ARRAY_SIZE
Definition app_queue.c:1588
static struct call_queue * find_load_queue_rt_friendly(const char *queuename)
Definition app_queue.c:4050
static struct ast_custom_function queuegetchannel_function
Definition app_queue.c:9628
static struct ast_manager_event_blob * queue_caller_abandon_to_ami(struct stasis_message *message)
Definition app_queue.c:2279
static struct stasis_forward * topic_forwarder
static struct ast_custom_function queueexists_function
Definition app_queue.c:9612
aqm_args
Definition app_queue.c:1622
@ AQM_OPT_ARG_ARRAY_SIZE
Definition app_queue.c:1624
@ AQM_OPT_ARG_PAUSE_REASON
Definition app_queue.c:1623
static int strat2int(const char *strategy)
Definition app_queue.c:2070
static int queue_function_queuegetchannel(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Dialplan function QUEUE_GET_CHANNEL() Get caller channel waiting at specified position in the queue.
Definition app_queue.c:9380
static struct ast_manager_event_blob * queue_agent_complete_to_ami(struct stasis_message *message)
Definition app_queue.c:2409
static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags *opts, char *opt_args[])
Definition app_queue.c:7020
static int word_in_list(const char *list, const char *word)
Check if a given word is in a space-delimited list.
static void log_attended_transfer(struct queue_stasis_data *queue_data, struct ast_attended_transfer_message *atxfer_msg)
Definition app_queue.c:6485
static int ring_one(struct queue_ent *qe, struct callattempt *outgoing, int *busies)
Place a call to a queue member.
Definition app_queue.c:5065
@ OPT_CALLER_AUTOMON
Definition app_queue.c:1576
@ OPT_CALLEE_PARK
Definition app_queue.c:1566
@ OPT_PREDIAL_CALLER
Definition app_queue.c:1578
@ OPT_GO_ON
Definition app_queue.c:1559
@ OPT_IGNORE_CONNECTEDLINE
Definition app_queue.c:1565
@ OPT_CALLEE_AUTOMON
Definition app_queue.c:1575
@ OPT_CALLEE_TRANSFER
Definition app_queue.c:1571
@ OPT_CALLEE_GO_ON
Definition app_queue.c:1561
@ OPT_MARK_AS_ANSWERED
Definition app_queue.c:1558
@ OPT_IGNORE_CALL_FW
Definition app_queue.c:1564
@ OPT_CALLER_PARK
Definition app_queue.c:1567
@ OPT_NO_RETRY
Definition app_queue.c:1568
@ OPT_DATA_QUALITY
Definition app_queue.c:1560
@ OPT_CALLER_HANGUP
Definition app_queue.c:1563
@ OPT_MUSICONHOLD_CLASS
Definition app_queue.c:1579
@ OPT_CALLEE_AUTOMIXMON
Definition app_queue.c:1573
@ OPT_CALLEE_HANGUP
Definition app_queue.c:1562
@ OPT_CALLER_AUTOMIXMON
Definition app_queue.c:1574
@ OPT_RINGING
Definition app_queue.c:1569
@ OPT_CALLER_TRANSFER
Definition app_queue.c:1572
@ OPT_PREDIAL_CALLEE
Definition app_queue.c:1577
@ OPT_RING_WHEN_RINGING
Definition app_queue.c:1570
static const struct @51 queue_results[]
static void handle_blind_transfer(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
Handle a blind transfer event.
Definition app_queue.c:6564
static const struct autopause autopausesmodes[]
agent_complete_reason
Definition app_queue.c:6277
@ AGENT
Definition app_queue.c:6279
@ CALLER
Definition app_queue.c:6278
@ TRANSFER
Definition app_queue.c:6280
static struct ast_manager_event_blob * queue_member_to_ami(const char *type, struct stasis_message *message)
Definition app_queue.c:2294
@ QUEUE_STRATEGY_RINGALL
Definition app_queue.c:1633
@ QUEUE_STRATEGY_RRMEMORY
Definition app_queue.c:1637
@ QUEUE_STRATEGY_LINEAR
Definition app_queue.c:1638
@ QUEUE_STRATEGY_LEASTRECENT
Definition app_queue.c:1634
@ QUEUE_STRATEGY_RANDOM
Definition app_queue.c:1636
@ QUEUE_STRATEGY_FEWESTCALLS
Definition app_queue.c:1635
@ QUEUE_STRATEGY_RRORDERED
Definition app_queue.c:1640
@ QUEUE_STRATEGY_WRANDOM
Definition app_queue.c:1639
static int autopause2int(const char *autopause)
Definition app_queue.c:2083
static int manager_change_priority_caller_on_queue(struct mansession *s, const struct message *m)
static int compress_char(const char c)
Definition app_queue.c:3050
static void queue_publish_member_blob(struct stasis_message_type *type, struct ast_json *blob)
Definition app_queue.c:2506
@ QUEUE_AUTOPAUSE_ON
Definition app_queue.c:1645
@ QUEUE_AUTOPAUSE_OFF
Definition app_queue.c:1644
@ QUEUE_AUTOPAUSE_ALL
Definition app_queue.c:1646
static int manager_queue_log_custom(struct mansession *s, const struct message *m)
static struct ast_manager_event_blob * queue_caller_leave_to_ami(struct stasis_message *message)
Definition app_queue.c:2274
static int try_calling(struct queue_ent *qe, struct ast_flags opts, char **opt_args, char *announceoverride, const char *url, int *tries, int *noption, const char *agi, const char *gosub, int ringing)
Definition app_queue.c:7141
static int set_member_penalty_help_members(struct call_queue *q, const char *interface, int penalty)
Definition app_queue.c:8080
unsigned int stop
Definition app_sla.c:342
ast_mutex_t lock
Definition app_sla.c:337
#define var
Definition ast_expr2f.c:605
Persistent data storage (akin to *doze registry)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition db.c:335
int ast_db_get_allocated(const char *family, const char *key, char **out)
Get key value specified by family/key as a heap allocated string.
Definition db.c:431
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition db.c:472
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
Definition db.c:635
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Definition db.c:695
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define PATH_MAX
Definition asterisk.h:40
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
#define ast_log
Definition astobj2.c:42
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ CMP_MATCH
Definition astobj2.h:1027
@ CMP_STOP
Definition astobj2.h:1028
#define OBJ_KEY
Definition astobj2.h:1151
#define OBJ_POINTER
Definition astobj2.h:1150
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_t_iterator_next(iter, tag)
Definition astobj2.h:1909
#define ao2_t_find(container, arg, flags, tag)
Definition astobj2.h:1734
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition astobj2.h:1693
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
@ AO2_ITERATOR_UNLINK
Definition astobj2.h:1863
@ AO2_ITERATOR_DONTLOCK
Assume that the ao2_container is already locked.
Definition astobj2.h:1852
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define AO2_STRING_FIELD_SORT_FN(stype, field)
Creates a sort function for a structure string field.
Definition astobj2.h:2064
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a red-black tree container.
Definition astobj2.h:1349
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Definition astobj2.h:407
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition astobj2.h:1087
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition astobj2.h:1063
@ OBJ_NODATA
Definition astobj2.h:1044
@ OBJ_SEARCH_MASK
Search option field mask.
Definition astobj2.h:1072
@ OBJ_MULTIPLE
Definition astobj2.h:1049
@ OBJ_UNLINK
Definition astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition astobj2.h:1101
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition bridge.h:1104
After Bridge Execution API.
void ast_bridge_set_after_go_on(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *parseable_goto)
Set channel to go on in the dialplan after the bridge.
static void ringing(struct ast_channel *chan)
Helper method to send a ringing indication to a channel in a bridge.
Basic bridge subclass API.
#define AST_TRANSFERER_ROLE_NAME
@ AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM
@ AST_BRIDGE_FLAG_MERGE_INHIBIT_TO
@ AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
int ast_channel_has_role(struct ast_channel *channel, const char *role_name)
Check if a role exists on a channel.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define AST_PRES_ALLOWED
Definition callerid.h:432
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
Definition callerid.h:554
#define AST_PRES_RESTRICTION
Definition callerid.h:431
Internal Asterisk hangup causes.
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition causes.h:114
static int priority
static int connected
Definition cdr_pgsql.c:73
static int available(struct dahdi_pvt **pvt, int is_specific_channel)
static const char type[]
static int call(void *data)
General Asterisk PBX channel definitions.
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition channel.c:3172
const char * ast_channel_name(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition channel.c:2108
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition channel.c:6456
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame)
Run a connected line interception subroutine and update a channel's connected line information.
Definition channel.c:10382
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition channel.c:1630
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2538
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition channel.h:1525
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition channel.c:1807
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition channel.c:2058
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition channel.c:7384
struct ast_channel * ast_waitfor_n(struct ast_channel **chan, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition channel.c:3154
#define ast_channel_lock(chan)
Definition channel.h:2982
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition channel.c:6715
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
void ast_channel_data_set(struct ast_channel *chan, const char *value)
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition channel.c:2017
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
Set the connected line information based on another connected line source.
Definition channel.c:2040
int ast_channel_priority(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2989
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition channel.c:2358
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition channel.c:6429
const char * ast_channel_context(const struct ast_channel *chan)
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4250
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Indicate that the connected line information has changed.
Definition channel.c:9137
ast_channel_adsicpe
Definition channel.h:888
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition channel.c:1985
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition channel.c:7346
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel's redirecting information.
Definition channel.c:10427
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition channel.c:6771
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1416
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition channel.c:8829
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition channel.c:6618
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition channel.c:445
int ast_channel_hangupcause(const struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition channel.c:4648
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition channel.c:10328
#define AST_CHANNEL_NAME
Definition channel.h:173
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition channel.c:1677
#define AST_MAX_CONTEXT
Definition channel.h:135
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition channel.c:2008
int ast_channel_sendurl(struct ast_channel *channel, const char *url)
Sends a URL on a given link Send URL on link.
Definition channel.c:6630
const char * ast_channel_language(const struct ast_channel *chan)
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition channel.c:2165
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition channel.c:8337
void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition channel.c:6434
const char * ast_channel_call_forward(const struct ast_channel *chan)
int ast_pre_call(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel before a call is placed.
Definition channel.c:6439
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition channel.c:7434
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation.
Definition channel.c:2031
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer)
Put chan into autoservice while hanging up peer.
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition channel.c:4270
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition channel.c:1560
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition channel.c:6349
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2983
#define AST_MAX_EXTENSION
Definition channel.h:134
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition channel.c:2121
#define MAX_MUSICCLASS
Definition channel.h:175
@ AST_FEATURE_AUTOMIXMON
Definition channel.h:1089
@ AST_FEATURE_REDIRECT
Definition channel.h:1084
@ AST_FEATURE_PARKCALL
Definition channel.h:1088
@ AST_FEATURE_AUTOMON
Definition channel.h:1087
@ AST_FEATURE_DISCONNECT
Definition channel.h:1085
ast_channel_state
ast_channel states
@ AST_STATE_UP
size_t current
Standard Command Line Interface.
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
#define RESULT_SUCCESS
Definition cli.h:40
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
#define CLI_FAILURE
Definition cli.h:46
#define RESULT_FAILURE
Definition cli.h:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
short word
#define SENTINEL
Definition compiler.h:87
Local proxy channel special access.
struct stasis_message_type * ast_local_optimization_end_type(void)
Message type for when a local channel optimization completes.
struct stasis_message_type * ast_local_optimization_begin_type(void)
Message type for when a local channel optimization begins.
Device state management.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
@ AST_DEVSTATE_CACHABLE
Definition devicestate.h:70
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
ast_device_state
Device States.
Definition devicestate.h:52
@ AST_DEVICE_RINGINUSE
Definition devicestate.h:60
@ AST_DEVICE_INUSE
Definition devicestate.h:55
@ AST_DEVICE_UNKNOWN
Definition devicestate.h:53
@ AST_DEVICE_ONHOLD
Definition devicestate.h:61
@ AST_DEVICE_RINGING
Definition devicestate.h:59
@ AST_DEVICE_INVALID
Definition devicestate.h:57
@ AST_DEVICE_BUSY
Definition devicestate.h:56
@ AST_DEVICE_NOT_INUSE
Definition devicestate.h:54
@ AST_DEVICE_UNAVAILABLE
Definition devicestate.h:58
Dialing API.
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition dial.c:749
char buf[BUFSIZE]
Definition eagi_proxy.c:66
#define abs(x)
Definition f2c.h:195
long int flag
Definition f2c.h:83
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
int ast_bridge_call_with_flags(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, unsigned int flags)
Bridge a call, and add additional flags to the bridge.
Definition features.c:604
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition file.c:223
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition file.c:1312
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition file.c:1148
#define AST_DIGIT_ANY
Definition file.h:48
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition file.c:1874
static const char name[]
Definition format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition manager.c:2024
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition manager.c:1982
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition manager.c:2060
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition manager.c:450
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition manager.c:2014
struct ast_str * ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
Convert a JSON object into an AMI compatible string.
Definition manager.c:551
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition manager.c:1643
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition manager.c:2068
void astman_append(struct mansession *s, const char *fmt,...)
Definition manager.c:1903
static struct stasis_topic * manager_topic
A stasis_topic that all topics AMI cares about will be forwarded to.
Definition manager.c:182
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition manager.c:7698
struct stasis_message_type * ast_channel_masquerade_type(void)
Message type for when a channel is being masqueraded.
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
struct ast_multi_channel_blob * ast_multi_channel_blob_create(struct ast_json *blob)
Create a ast_multi_channel_blob suitable for a stasis_message.
struct ast_channel_snapshot * ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
Retrieve a channel snapshot associated with a specific role from a ast_multi_channel_blob.
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message using the latest snapshot from the cache.
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
struct stasis_message_type * ast_channel_agent_logoff_type(void)
Message type for agent logoff on a channel.
struct ast_channel_snapshot * ast_channel_snapshot_create(struct ast_channel *chan)
Generate a snapshot of the channel state. This is an ao2 object, so ao2_cleanup() to deallocate.
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
Add a ast_channel_snapshot to a ast_multi_channel_blob object.
struct stasis_message_type * ast_channel_hangup_request_type(void)
Message type for when a hangup is requested on a channel.
struct stasis_message_type * ast_channel_agent_login_type(void)
Message type for agent login on a channel.
struct ast_json * ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
Retrieve the JSON blob from a ast_multi_channel_blob. Returned ast_json is still owned by obj.
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define END_OPTIONS
struct stasis_topic * ast_queue_topic(const char *queuename)
Get the Stasis Message Bus API topic for queue messages for a particular queue name.
Definition main/app.c:3349
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define BEGIN_OPTIONS
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
struct stasis_topic * ast_queue_topic_all(void)
Get the Stasis Message Bus API topic for queue messages.
Definition main/app.c:3344
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition main/app.c:297
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition main/app.c:3066
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition extconf.c:3324
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition extconf.c:3272
int ast_realtime_require_field(const char *family,...) attribute_sentinel
Inform realtime what fields that may be stored.
struct ast_config * ast_load_realtime_multientry(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
@ CONFIG_FLAG_FILEUNCHANGED
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
int ast_update_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Update realtime configuration.
struct ast_variable * ast_load_realtime(const char *family,...) attribute_sentinel
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
#define AST_FRAME_DTMF
#define AST_OPTION_TONE_VERIFY
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_PVT_CAUSE_CODE
#define ast_debug(level,...)
Log a DEBUG message.
void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
Definition logger.c:957
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
Definition json.c:756
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition json.c:332
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition json.h:87
A set of macros to manage forward-linked lists.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_INSERT_BEFORE_CURRENT(elm, field)
Inserts a list entry before the current entry during a traversal.
#define AST_LIST_LOCK(head)
Locks a list.
Definition linkedlists.h:40
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk locking-related definitions:
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Definition lock.h:611
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition lock.h:764
int errno
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition manager.h:192
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition manager.c:10144
#define EVENT_FLAG_AGENT
Definition manager.h:80
struct ast_str * ast_manager_build_channel_state_string_prefix(const struct ast_channel_snapshot *snapshot, const char *prefix)
Generate the AMI message body from a channel snapshot.
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
loadable MixMonitor functionality
int ast_start_mixmonitor(struct ast_channel *chan, const char *filename, const char *options)
Start a mixmonitor on a channel with the given parameters.
Definition mixmonitor.c:74
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition module.h:557
@ AST_MODPRI_DEVSTATE_CONSUMER
Definition module.h:347
@ AST_MODULE_SUPPORT_CORE
Definition module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640
Music on hold handling.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition channel.c:7778
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition channel.c:7788
Core PBX routines and definitions.
const struct ast_include * ast_walk_context_includes(const struct ast_context *con, const struct ast_include *inc)
Definition pbx.c:8675
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition extconf.c:4170
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition pbx.c:4196
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition pbx_app.c:471
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
const char * ast_get_include_name(const struct ast_include *include)
Definition pbx_include.c:50
int pbx_builtin_setvar_multiple(struct ast_channel *chan, const char *data)
Parse and set multiple channel variables, where the pairs are separated by the ',' character,...
@ AST_EXTENSION_REMOVED
Definition pbx.h:62
@ AST_EXTENSION_RINGING
Definition pbx.h:68
@ AST_EXTENSION_NOT_INUSE
Definition pbx.h:64
@ AST_EXTENSION_INUSE
Definition pbx.h:65
@ AST_EXTENSION_UNAVAILABLE
Definition pbx.h:67
@ AST_EXTENSION_ONHOLD
Definition pbx.h:69
@ AST_EXTENSION_BUSY
Definition pbx.h:66
@ AST_EXTENSION_DEACTIVATED
Definition pbx.h:63
const char * ast_get_context_name(struct ast_context *con)
Definition ael_main.c:421
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562
int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition pbx.c:8806
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition pbx.c:4211
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_extension_state_del(int id, ast_state_cb_type change_cb)
Deletes a state change watcher by ID.
Definition pbx.c:3877
@ AST_HINT_UPDATE_DEVICE
Definition pbx.h:91
int ast_extension_state_add(const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
Add watcher for extension states.
Definition pbx.c:3844
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition ael_main.c:165
int ast_extension_state(struct ast_channel *c, const char *context, const char *exten)
Uses hint and devicestate callback to get the state of an extension.
Definition pbx.c:3191
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition ael_main.c:211
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
static char url[512]
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
static struct @519 args
#define NULL
Definition resample.c:96
Say numbers and dates (maybe words one day too)
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
Definition channel.c:8279
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition stasis.h:1515
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition stasis.h:297
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition stasis.c:1615
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition stasis.c:1090
#define STASIS_MESSAGE_TYPE_DEFN_LOCAL(name,...)
Boiler-plate messaging macro for defining local message types.
Definition stasis.h:1467
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition stasis.c:1144
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition stasis.h:1493
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
int stasis_subscription_final_message(struct stasis_subscription *sub, struct stasis_message *msg)
Determine whether a message is the final message to be received on a subscription.
Definition stasis.c:1241
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Definition stasis.c:1201
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition stasis.c:1645
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
#define stasis_subscribe(topic, callback, data)
Definition stasis.h:649
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for ast_channel enter bridge blob messages.
struct stasis_message_type * ast_blind_transfer_type(void)
Message type for ast_blind_transfer_message.
struct stasis_message_type * ast_attended_transfer_type(void)
Message type for ast_attended_transfer_message.
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.
@ AST_ATTENDED_TRANSFER_DEST_FAIL
@ AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE
@ AST_ATTENDED_TRANSFER_DEST_LOCAL_APP
@ AST_ATTENDED_TRANSFER_DEST_LINK
@ AST_ATTENDED_TRANSFER_DEST_APP
@ AST_ATTENDED_TRANSFER_DEST_THREEWAY
#define stasis_message_router_create(topic)
Create a new message router object.
void stasis_message_router_unsubscribe(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed.
#define stasis_message_router_create_pool(topic)
Create a new message router object.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition strings.c:238
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2235
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
@ AST_STRSEP_TRIM
Definition strings.h:256
@ AST_STRSEP_STRIP
Definition strings.h:255
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition utils.c:2252
#define ast_str_alloca(init_len)
Definition strings.h:848
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition strings.h:1303
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition utils.c:1871
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
ast_app: A registered application
Definition pbx_app.c:45
Message representing attended transfer.
enum ast_attended_transfer_dest_type dest_type
struct ast_channel_snapshot * links[2]
struct ast_bridge_channel_snapshot_pair to_transfer_target
enum ast_transfer_result result
union ast_attended_transfer_message::@305 dest
struct ast_bridge_channel_snapshot_pair to_transferee
char bridge[AST_UUID_STR_LEN]
Message published during a blind transfer.
char exten[AST_MAX_EXTENSION]
struct ast_bridge_snapshot * bridge
enum ast_transfer_result result
char context[AST_MAX_CONTEXT]
Blob of data associated with a bridge.
struct ast_bridge_snapshot * bridge
struct ast_channel_snapshot * channel
struct ast_bridge_snapshot * bridge_snapshot
bridge configuration
Definition channel.h:1096
void * end_bridge_callback_data
Definition channel.h:1111
struct ast_flags features_callee
Definition channel.h:1098
struct ast_flags features_caller
Definition channel.h:1097
void(* end_bridge_callback)(void *)
Definition channel.h:1110
void(* end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition channel.h:1115
const ast_string_field uniqueid
Definition bridge.h:332
Blob of data associated with a channel.
struct ast_channel_snapshot * snapshot
struct ast_json * blob
const ast_string_field uniqueid
const ast_string_field name
Structure representing a snapshot of channel state.
struct ast_channel_snapshot_base * base
struct ast_channel_snapshot_caller * caller
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition channel.h:648
const char *const type
Definition channel.h:649
Main Channel structure associated with a channel.
const struct ast_channel_tech * tech
char context[AST_MAX_CONTEXT]
descriptor for a cli entry.
Definition cli.h:171
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
ast_context: An extension context
Definition pbx.c:299
Data structure associated with a custom dialplan function.
Definition pbx.h:118
const char * name
Definition pbx.h:119
Definition astdb.h:31
struct ast_db_entry * next
Definition astdb.h:32
char * key
Definition astdb.h:33
The structure that contains device state.
enum ast_device_state state
const struct ast_eid * eid
The EID of the server where this message originated.
Structure used to handle boolean flags.
Definition utils.h:220
unsigned int flags
Definition utils.h:221
Format capabilities structure, holds formats + preference order + etc.
Definition format_cap.c:54
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@239 data
ast_include: include= support in extensions.conf
Definition pbx_include.c:37
struct ast_json * json
Definition json.h:1083
Abstract JSON element (object, array, string, int, ...).
Struct containing info for an AMI event to send out.
Definition manager.h:503
A multi channel blob data structure for multi_channel_blob stasis messages.
Caller Party information.
Definition channel.h:420
struct ast_party_id id
Caller party ID.
Definition channel.h:422
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition channel.h:429
Connected Line/Party information.
Definition channel.h:458
int source
Information about the source of an update.
Definition channel.h:484
struct ast_party_id id
Connected party ID.
Definition channel.h:460
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition channel.h:467
char * str
Subscriber phone number (Malloced)
Definition channel.h:388
struct ast_party_dialed::@221 number
Dialed/Called number.
int transit_network_select
Transit Network Select.
Definition channel.h:399
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition channel.h:524
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529
Support for dynamic strings.
Definition strings.h:623
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
int autopause
Definition app_queue.c:1672
const char * name
Definition app_queue.c:1673
unsigned int autopauseunavail
Definition app_queue.c:1984
const ast_string_field sound_thereare
Definition app_queue.c:1964
unsigned int setinterfacevar
Definition app_queue.c:1970
struct ast_str * sound_periodicannounce[MAX_PERIODIC_ANNOUNCEMENTS]
Definition app_queue.c:1966
const ast_string_field sound_callerannounce
Definition app_queue.c:1964
int announcefrequency
Definition app_queue.c:1988
const ast_string_field sound_reporthold
Definition app_queue.c:1964
unsigned int announceholdtime
Definition app_queue.c:1976
const ast_string_field sound_holdtime
Definition app_queue.c:1964
unsigned int dead
Definition app_queue.c:1967
unsigned int reportholdtime
Definition app_queue.c:1973
unsigned int setqueueentryvar
Definition app_queue.c:1972
const ast_string_field sound_seconds
Definition app_queue.c:1964
unsigned int timeoutrestart
Definition app_queue.c:1975
struct ao2_container * members
Definition app_queue.c:2022
int periodicannouncefrequency
Definition app_queue.c:1991
const ast_string_field sound_thanks
Definition app_queue.c:1964
unsigned int announceposition_only_up
Definition app_queue.c:1978
unsigned int setqueuevar
Definition app_queue.c:1971
int announcepositionlimit
Definition app_queue.c:1987
unsigned int announce_to_first_user
Definition app_queue.c:1969
int randomperiodicannounce
Definition app_queue.c:1993
int periodicannouncestartdelay
Definition app_queue.c:1990
const ast_string_field defaultrule
Definition app_queue.c:1964
int log_restricted_caller_id
Definition app_queue.c:2020
struct queue_ent * head
Definition app_queue.c:2023
unsigned int realtime
Definition app_queue.c:1980
const ast_string_field queue_quantity2
Definition app_queue.c:1964
int servicelevel
Definition app_queue.c:2000
const ast_string_field moh
Definition app_queue.c:1964
struct call_queue::@54 list
int minannouncefrequency
Definition app_queue.c:1989
enum empty_conditions leavewhenempty
Definition app_queue.c:1986
int penaltymemberslimit
Definition app_queue.c:2006
unsigned int found
Definition app_queue.c:1981
const ast_string_field context
Definition app_queue.c:1964
const ast_string_field sound_calls
Definition app_queue.c:1964
unsigned int ringinuse
Definition app_queue.c:1968
int callsabandoned
Definition app_queue.c:1998
int roundingseconds
Definition app_queue.c:1994
int numperiodicannounce
Definition app_queue.c:1992
const ast_string_field sound_minute
Definition app_queue.c:1964
int callscompleted
Definition app_queue.c:1997
int callsabandonedinsl
Definition app_queue.c:1999
const ast_string_field sound_minutes
Definition app_queue.c:1964
unsigned int announceposition
Definition app_queue.c:1977
const ast_string_field queue_quantity1
Definition app_queue.c:1964
const ast_string_field membergosub
Definition app_queue.c:1964
char monfmt[8]
Definition app_queue.c:2002
enum empty_conditions joinempty
Definition app_queue.c:1985
unsigned int wrapped
Definition app_queue.c:1974
struct call_queue::@55 rules
const ast_string_field name
Definition app_queue.c:1964
int callscompletedinsl
Definition app_queue.c:2001
int memberdelay
Definition app_queue.c:2017
const ast_string_field sound_next
Definition app_queue.c:1964
unsigned int autopausebusy
Definition app_queue.c:1983
const ast_string_field announce
Definition app_queue.c:1964
int autopausedelay
Definition app_queue.c:2012
int timeoutpriority
Definition app_queue.c:2013
unsigned int relativeperiodicannounce
Definition app_queue.c:1982
We define a custom "local user" structure because we use it not only for keeping track of what is in ...
Definition app_queue.c:1802
unsigned int dial_callerid_absent
Definition app_queue.c:1816
unsigned int block_connected_update
Definition app_queue.c:1814
struct ast_aoc_decoded * aoc_s_rate_list
Definition app_queue.c:1819
struct ast_party_connected_line connected
Definition app_queue.c:1810
char interface[256]
Definition app_queue.c:1806
char * orig_chan_name
Definition app_queue.c:1821
struct callattempt * call_next
Definition app_queue.c:1804
struct ast_channel * chan
Definition app_queue.c:1805
unsigned int stillgoing
Definition app_queue.c:1818
struct callattempt * q_next
Definition app_queue.c:1803
struct member * member
Definition app_queue.c:1808
unsigned int pending_connected_update
Definition app_queue.c:1812
structure to hold extensions
Structure representing relevant data during a local channel optimization.
Definition app_queue.c:6353
const char * source_chan_uniqueid
Definition app_queue.c:6355
unsigned int id
Definition app_queue.c:6359
In case you didn't read that giant block of text above the mansession_session struct,...
Definition manager.c:323
Channel datastore data for max forwards.
char interface[AST_CHANNEL_NAME]
Definition app_queue.c:1861
unsigned int dead
Definition app_queue.c:1882
unsigned int delme
Definition app_queue.c:1883
int queuepos
Definition app_queue.c:1874
time_t starttime
Definition app_queue.c:1877
time_t lastcall
Definition app_queue.c:1878
int dynamic
Definition app_queue.c:1869
time_t logintime
Definition app_queue.c:1880
char membername[80]
Definition app_queue.c:1866
char rt_uniqueid[80]
Definition app_queue.c:1884
int calls
Definition app_queue.c:1868
int status
Definition app_queue.c:1871
int penalty
Definition app_queue.c:1867
int paused
Definition app_queue.c:1872
unsigned int ringinuse
Definition app_queue.c:1885
int wrapuptime
Definition app_queue.c:1876
int callcompletedinsl
Definition app_queue.c:1875
char state_exten[AST_MAX_EXTENSION]
Definition app_queue.c:1862
char state_context[AST_MAX_CONTEXT]
Definition app_queue.c:1863
int realtime
Definition app_queue.c:1870
int state_id
Definition app_queue.c:1865
time_t lastpause
Definition app_queue.c:1879
char reason_paused[80]
Definition app_queue.c:1873
struct call_queue * lastqueue
Definition app_queue.c:1881
char state_interface[AST_CHANNEL_NAME]
Definition app_queue.c:1864
Number structure.
int raise_respect_min
Definition app_queue.c:1917
struct penalty_rule::@53 list
struct call_queue * q
Definition app_queue.c:6986
struct ast_channel * chan
Definition app_queue.c:6987
int raise_respect_min
Definition app_queue.c:1846
char digits[AST_MAX_EXTENSION]
Definition app_queue.c:1830
int valid_digits
Definition app_queue.c:1832
time_t last_pos
Definition app_queue.c:1839
time_t last_periodic_announce_time
Definition app_queue.c:1837
time_t expire
Definition app_queue.c:1850
unsigned int withdraw
Definition app_queue.c:1852
struct penalty_rule * pr
Definition app_queue.c:1856
struct queue_ent::@52 qe_rules
int max_penalty
Definition app_queue.c:1843
int raise_penalty
Definition app_queue.c:1845
struct ast_channel * chan
Definition app_queue.c:1854
int min_penalty
Definition app_queue.c:1844
int ring_when_ringing
Definition app_queue.c:1836
int cancel_answered_elsewhere
Definition app_queue.c:1851
char announce[PATH_MAX]
Definition app_queue.c:1828
char * withdraw_info
Definition app_queue.c:1853
int linwrapped
Definition app_queue.c:1848
char moh[MAX_MUSICCLASS]
Definition app_queue.c:1827
int last_pos_said
Definition app_queue.c:1835
char context[AST_MAX_CONTEXT]
Definition app_queue.c:1829
int last_periodic_announce_sound
Definition app_queue.c:1838
const char * predial_callee
Definition app_queue.c:1831
time_t start
Definition app_queue.c:1849
struct call_queue * parent
Definition app_queue.c:1826
struct queue_ent * next
Definition app_queue.c:1857
User data for stasis subscriptions used for queue calls.
Definition app_queue.c:6377
const ast_string_field caller_uniqueid
Definition app_queue.c:6385
const ast_string_field member_uniqueid
Definition app_queue.c:6385
struct local_optimization member_optimize
Definition app_queue.c:6407
struct stasis_message_router * channel_router
Definition app_queue.c:6403
struct call_queue * queue
Definition app_queue.c:6387
const ast_string_field bridge_uniqueid
Definition app_queue.c:6385
struct stasis_message_router * bridge_router
Definition app_queue.c:6401
struct local_optimization caller_optimize
Definition app_queue.c:6405
struct member * member
Definition app_queue.c:6389
char name[80]
Definition app_queue.c:2029
struct rule_list::@57 list
struct rule_list::@56 rules
Forwarding information.
Definition stasis.c:1598
const char * name
Definition app_queue.c:1658
int strategy
Definition app_queue.c:1657
int value
Definition syslog.c:37
An API for managing task processing threads that can be shared across modules.
Handy terminal functions for vt* terms.
const char * ast_term_reset(void)
Returns the terminal reset code.
Definition term.c:357
#define COLOR_CYAN
Definition term.h:62
#define COLOR_MAGENTA
Definition term.h:60
#define COLOR_BROWN
Definition term.h:56
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
Definition term.c:341
#define COLOR_BLACK
Definition term.h:50
#define COLOR_RED
Definition term.h:52
#define COLOR_GREEN
Definition term.h:54
static struct test_options options
static struct test_val a
static struct test_val c
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2317
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159
Support for translation of data formats. translate.c.
FILE * out
Definition utils/frame.c:33
FILE * in
Definition utils/frame.c:33
Utility functions.
#define ast_test_flag(p, flag)
Definition utils.h:64
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define ast_assert(a)
Definition utils.h:779
long int ast_random(void)
Definition utils.c:2348
#define ast_set_flag(p, flag)
Definition utils.h:71
#define ARRAY_LEN(a)
Definition utils.h:706
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition utils.c:2379
#define AST_FLAGS_ALL
Definition utils.h:217