Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
app_directed_pickup.c File Reference

Directed Call Pickup Support. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/pickup.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"

Go to the source code of this file.

Data Structures

struct  pickup_by_name_args
 

Macros

#define PICKUPMARK   "PICKUPMARK"
 

Enumerations

enum  OPT_PICKUPCHAN_FLAGS { OPT_PICKUPCHAN_PARTIAL = (1 << 0) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_channelfind_by_channel (struct ast_channel *chan, const char *channame)
 Helper Function to walk through ALL channels checking NAME and STATE.
 
static int find_by_mark (void *obj, void *arg, void *data, int flags)
 
static int find_by_name (void *obj, void *arg, void *data, int flags)
 
static struct ast_channelfind_by_part (struct ast_channel *chan, const char *part)
 
static int find_by_uniqueid (void *obj, void *arg, void *data, int flags)
 
static int load_module (void)
 
static int pickup_by_channel (struct ast_channel *chan, const char *name)
 Attempt to pick up named channel. More...
 
static int pickup_by_exten (struct ast_channel *chan, const char *exten, const char *context)
 
static int pickup_by_group (struct ast_channel *chan)
 
static int pickup_by_mark (struct ast_channel *chan, const char *mark)
 
static int pickup_by_part (struct ast_channel *chan, const char *part)
 
static int pickup_exec (struct ast_channel *chan, const char *data)
 
static int pickupchan_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Directed Call Pickup Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char app [] = "Pickup"
 
static const char app2 [] = "PickupChan"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_app_option pickupchan_opts [128] = { [ 'p' ] = { .flag = OPT_PICKUPCHAN_PARTIAL }, }
 

Detailed Description

Directed Call Pickup Support.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om
Gary Cook

Definition in file app_directed_pickup.c.

Function Documentation

static int find_by_mark ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

< Potential pickup target

Definition at line 268 of file app_directed_pickup.c.

References ast_can_pickup(), CMP_MATCH, CMP_STOP, ast_channel::data, and pbx_builtin_getvar_helper().

Referenced by pickup_by_mark().

269 {
270  struct ast_channel *target = obj;/*!< Potential pickup target */
271  struct ast_channel *chan = arg;
272  const char *mark = data;
273  const char *tmp;
274 
275  if (chan == target) {
276  /* The channel attempting to pickup a call cannot pickup itself. */
277  return 0;
278  }
279 
280  ast_channel_lock(target);
281  tmp = pbx_builtin_getvar_helper(target, PICKUPMARK);
282  if (tmp && !strcasecmp(tmp, mark) && ast_can_pickup(target)) {
283  /* Return with the channel still locked on purpose */
284  return CMP_MATCH | CMP_STOP;
285  }
286  ast_channel_unlock(target);
287 
288  return 0;
289 }
Main Channel structure associated with a channel.
const char * data
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_can_pickup(struct ast_channel *chan)
Test if a channel can be picked up.
Definition: pickup.c:77
static int find_by_name ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

< Potential pickup target

Definition at line 137 of file app_directed_pickup.c.

References ast_can_pickup(), pickup_by_name_args::chan, CMP_MATCH, CMP_STOP, pickup_by_name_args::len, and pickup_by_name_args::name.

Referenced by ast_setlocale(), and find_by_channel().

138 {
139  struct ast_channel *target = obj;/*!< Potential pickup target */
140  struct pickup_by_name_args *args = data;
141 
142  if (args->chan == target) {
143  /* The channel attempting to pickup a call cannot pickup itself. */
144  return 0;
145  }
146 
147  ast_channel_lock(target);
148  if (!strncasecmp(ast_channel_name(target), args->name, args->len)
149  && ast_can_pickup(target)) {
150  /* Return with the channel still locked on purpose */
151  return CMP_MATCH | CMP_STOP;
152  }
153  ast_channel_unlock(target);
154 
155  return 0;
156 }
Main Channel structure associated with a channel.
struct ast_channel * chan
int ast_can_pickup(struct ast_channel *chan)
Test if a channel can be picked up.
Definition: pickup.c:77
static int find_by_uniqueid ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

< Potential pickup target

Definition at line 158 of file app_directed_pickup.c.

References ast_can_pickup(), pickup_by_name_args::chan, CMP_MATCH, CMP_STOP, and pickup_by_name_args::name.

Referenced by find_by_channel().

159 {
160  struct ast_channel *target = obj;/*!< Potential pickup target */
161  struct pickup_by_name_args *args = data;
162 
163  if (args->chan == target) {
164  /* The channel attempting to pickup a call cannot pickup itself. */
165  return 0;
166  }
167 
168  ast_channel_lock(target);
169  if (!strcasecmp(ast_channel_uniqueid(target), args->name)
170  && ast_can_pickup(target)) {
171  /* Return with the channel still locked on purpose */
172  return CMP_MATCH | CMP_STOP;
173  }
174  ast_channel_unlock(target);
175 
176  return 0;
177 }
Main Channel structure associated with a channel.
struct ast_channel * chan
int ast_can_pickup(struct ast_channel *chan)
Test if a channel can be picked up.
Definition: pickup.c:77
static int pickup_by_channel ( struct ast_channel chan,
const char *  name 
)
static

Attempt to pick up named channel.

< Potential pickup target

Definition at line 220 of file app_directed_pickup.c.

References ast_channel_unref, ast_do_pickup(), and find_by_channel().

221 {
222  int res = -1;
223  struct ast_channel *target;/*!< Potential pickup target */
224 
225  /* The found channel is already locked. */
226  target = find_by_channel(chan, name);
227  if (target) {
228  res = ast_do_pickup(chan, target);
229  ast_channel_unlock(target);
230  target = ast_channel_unref(target);
231  }
232 
233  return res;
234 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
Pickup a call target.
Definition: pickup.c:301
static struct ast_channel * find_by_channel(struct ast_channel *chan, const char *channame)
Helper Function to walk through ALL channels checking NAME and STATE.
const ast_string_field name
static int pickup_by_exten ( struct ast_channel chan,
const char *  exten,
const char *  context 
)
static

< Potential pickup target

Definition at line 237 of file app_directed_pickup.c.

References ast_can_pickup(), ast_channel_iterator_by_exten_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_unref, and ast_do_pickup().

238 {
239  struct ast_channel *target = NULL;/*!< Potential pickup target */
240  struct ast_channel_iterator *iter;
241  int res = -1;
242 
243  if (!(iter = ast_channel_iterator_by_exten_new(exten, context))) {
244  return -1;
245  }
246 
247  while ((target = ast_channel_iterator_next(iter))) {
248  ast_channel_lock(target);
249  if ((chan != target) && ast_can_pickup(target)) {
250  ast_log(LOG_NOTICE, "%s pickup by %s\n", ast_channel_name(target), ast_channel_name(chan));
251  break;
252  }
253  ast_channel_unlock(target);
254  target = ast_channel_unref(target);
255  }
256 
258 
259  if (target) {
260  res = ast_do_pickup(chan, target);
261  ast_channel_unlock(target);
262  target = ast_channel_unref(target);
263  }
264 
265  return res;
266 }
Main Channel structure associated with a channel.
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1422
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
Pickup a call target.
Definition: pickup.c:301
struct ast_channel_iterator * ast_channel_iterator_by_exten_new(const char *exten, const char *context)
Create a new channel iterator based on extension.
Definition: channel.c:1368
int ast_can_pickup(struct ast_channel *chan)
Test if a channel can be picked up.
Definition: pickup.c:77
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1360
static int pickup_by_group ( struct ast_channel chan)
static

< Potential pickup target

Definition at line 308 of file app_directed_pickup.c.

References ast_channel_unref, ast_do_pickup(), and ast_pickup_find_by_group().

309 {
310  struct ast_channel *target;/*!< Potential pickup target */
311  int res = -1;
312 
313  /* The found channel is already locked. */
314  target = ast_pickup_find_by_group(chan);
315  if (target) {
316  ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", ast_channel_name(target), ast_channel_name(chan));
317  res = ast_do_pickup(chan, target);
318  ast_channel_unlock(target);
319  target = ast_channel_unref(target);
320  }
321 
322  return res;
323 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
Pickup a call target.
Definition: pickup.c:301
struct ast_channel * ast_pickup_find_by_group(struct ast_channel *chan)
Find a pickup channel target by group.
Definition: pickup.c:133
static int pickup_by_mark ( struct ast_channel chan,
const char *  mark 
)
static

< Potential pickup target

Definition at line 292 of file app_directed_pickup.c.

References ast_channel_callback(), ast_channel_unref, ast_do_pickup(), and find_by_mark().

293 {
294  struct ast_channel *target;/*!< Potential pickup target */
295  int res = -1;
296 
297  /* The found channel is already locked. */
298  target = ast_channel_callback(find_by_mark, chan, (char *) mark, 0);
299  if (target) {
300  res = ast_do_pickup(chan, target);
301  ast_channel_unlock(target);
302  target = ast_channel_unref(target);
303  }
304 
305  return res;
306 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
Pickup a call target.
Definition: pickup.c:301
static int find_by_mark(void *obj, void *arg, void *data, int flags)
struct ast_channel * ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
Call a function with every active channel.
Definition: channel.c:1278
static int pickup_by_part ( struct ast_channel chan,
const char *  part 
)
static

< Potential pickup target

Definition at line 395 of file app_directed_pickup.c.

References ast_channel_unref, and ast_do_pickup().

396 {
397  struct ast_channel *target;/*!< Potential pickup target */
398  int res = -1;
399 
400  /* The found channel is already locked. */
401  target = find_by_part(chan, part);
402  if (target) {
403  res = ast_do_pickup(chan, target);
404  ast_channel_unlock(target);
405  target = ast_channel_unref(target);
406  }
407 
408  return res;
409 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
Pickup a call target.
Definition: pickup.c:301