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

Call Parking Applications. More...

#include "asterisk.h"
#include "res_parking.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/features.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/say.h"
#include "asterisk/bridge_basic.h"
#include "asterisk/format_cache.h"

Go to the source code of this file.

Data Structures

struct  park_announce_subscription_data
 

Macros

#define PARK_AND_ANNOUNCE_APPLICATION   "ParkAndAnnounce"
 

Enumerations

enum  park_args { OPT_ARG_COMEBACK, OPT_ARG_TIMEOUT, OPT_ARG_MUSICONHOLD, OPT_ARG_ARRAY_SIZE }
 
enum  park_flags {
  MUXFLAG_RINGING = (1 << 0), MUXFLAG_RANDOMIZE = (1 << 1), MUXFLAG_NOANNOUNCE = (1 << 2), MUXFLAG_COMEBACK_OVERRIDE = (1 << 3),
  MUXFLAG_TIMEOUT_OVERRIDE = (1 << 4), MUXFLAG_MUSICONHOLD = (1 << 5)
}
 

Functions

static void announce_to_dial (char *dial_string, char *announce_string, int parkingspace, struct ast_channel_snapshot *parkee_snapshot)
 
static int apply_option_timeout (int *var, char *timeout_arg)
 
struct park_common_datastoreget_park_common_datastore_copy (struct ast_channel *parkee)
 Get a copy of the park_common_datastore from a channel that is being parked. More...
 
static void inherit_channel_vars_from_id (struct outgoing_helper *oh, const char *channel_id)
 
int load_parking_applications (void)
 Register parking applications. More...
 
static int park_and_announce_app_exec (struct ast_channel *chan, const char *data)
 
static struct park_announce_subscription_datapark_announce_subscription_data_create (const char *parkee_uuid, const char *dial_string, const char *announce_string)
 
static void park_announce_subscription_data_destroy (void *data)
 
static void park_announce_update_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int park_app_exec (struct ast_channel *chan, const char *data)
 
static int park_app_parse_data (const char *data, int *disable_announce, int *use_ringing, int *randomize, int *time_limit, char **comeback_override, char **lot_name, char **musicclass)
 
struct ast_bridgepark_application_setup (struct ast_channel *parkee, struct ast_channel *parker, const char *app_data, int *silence_announcements)
 Function to prepare a channel for parking by determining which parking bridge should be used, setting up a park common datastore so that the parking bridge will have access to necessary parking information when joining, and applying various bridge roles to the channel. More...
 
static void park_common_datastore_destroy (void *data)
 
void park_common_datastore_free (struct park_common_datastore *datastore)
 Free a park common datastore struct. More...
 
struct ast_bridgepark_common_setup (struct ast_channel *parkee, struct ast_channel *parker, const char *lot_name, const char *comeback_override, int use_ringing, int randomize, int time_limit, int silence_announcements)
 Setup a parked call on a parking bridge without needing to parse appdata. More...
 
static struct ast_bridgepark_common_setup2 (struct ast_channel *parkee, struct ast_channel *parker, const char *lot_name, const char *comeback_override, const char *musicclass, int use_ringing, int randomize, int time_limit, int silence_announcements)
 
static int parked_call_app_exec (struct ast_channel *chan, const char *data)
 
static int setup_park_common_datastore (struct ast_channel *parkee, const char *parker_uuid, const char *comeback_override, int randomize, int time_limit, int silence_announce)
 
void unload_parking_applications (void)
 Unregister parking applications. More...
 
static void wipe_park_common_datastore (struct ast_channel *chan)
 

Variables

static const struct ast_datastore_info park_common_info
 
static const struct ast_app_option park_opts [128] = { [ 'r' ] = { .flag = MUXFLAG_RINGING }, [ 'R' ] = { .flag = MUXFLAG_RANDOMIZE }, [ 's' ] = { .flag = MUXFLAG_NOANNOUNCE }, [ 'c' ] = { .flag = MUXFLAG_COMEBACK_OVERRIDE , .arg_index = OPT_ARG_COMEBACK + 1 }, [ 't' ] = { .flag = MUXFLAG_TIMEOUT_OVERRIDE , .arg_index = OPT_ARG_TIMEOUT + 1 }, [ 'm' ] = { .flag = MUXFLAG_MUSICONHOLD , .arg_index = OPT_ARG_MUSICONHOLD + 1 }, }
 

Detailed Description

Call Parking Applications.

Author
Jonathan Rose jrose.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file parking_applications.c.

Function Documentation

struct park_common_datastore* get_park_common_datastore_copy ( struct ast_channel parkee)

Get a copy of the park_common_datastore from a channel that is being parked.

Since
12.0.0
Parameters
parkeeThe channel entering parking with the datastore we are checking
Returns
Pointer to a copy of the park common datastore for parkee if it could be cloned. This needs to be free'd with park_common_datastore free.
Return values
NULLif the park_common_datastore could not be copied off of the channel.

Definition at line 441 of file parking_applications.c.

References ast_calloc, ast_channel_datastore_find(), ast_strdup, park_common_datastore::comeback_override, ast_datastore::data, lock, park_common_datastore_free(), park_common_datastore::parker_dial_string, park_common_datastore::parker_uuid, park_common_datastore::randomize, SCOPED_CHANNELLOCK, park_common_datastore::silence_announce, and park_common_datastore::time_limit.

442 {
443  struct ast_datastore *datastore;
444  struct park_common_datastore *data;
445  struct park_common_datastore *data_copy;
446 
447  SCOPED_CHANNELLOCK(lock, parkee);
448 
449  if (!(datastore = ast_channel_datastore_find(parkee, &park_common_info, NULL))) {
450  return NULL;
451  }
452 
453  data = datastore->data;
454 
455  /* This data should always be populated if this datastore was appended to the channel */
456  ast_assert(data != NULL);
457 
458  data_copy = ast_calloc(1, sizeof(*data_copy));
459  if (!data_copy) {
460  return NULL;
461  }
462 
463  data_copy->parker_uuid = ast_strdup(data->parker_uuid);
464  if (!data_copy->parker_uuid) {
465  park_common_datastore_free(data_copy);
466  return NULL;
467  }
468 
469  data_copy->randomize = data->randomize;
470  data_copy->time_limit = data->time_limit;
471  data_copy->silence_announce = data->silence_announce;
472 
473  if (data->comeback_override) {
474  data_copy->comeback_override = ast_strdup(data->comeback_override);
475  if (!data_copy->comeback_override) {
476  park_common_datastore_free(data_copy);
477  return NULL;
478  }
479  }
480 
481  if (data->parker_dial_string) {
483  if (!data_copy->parker_dial_string) {
484  park_common_datastore_free(data_copy);
485  return NULL;
486  }
487  }
488 
489  return data_copy;
490 }
void park_common_datastore_free(struct park_common_datastore *datastore)
Free a park common datastore struct.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
Structure for a data store object.
Definition: datastore.h:64
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
ast_mutex_t lock
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition: lock.h:619
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
void * data
Definition: datastore.h:66
int load_parking_applications ( void  )

Register parking applications.

Since
12.0.0
Return values
0if successful
-1on failure

Definition at line 1008 of file parking_applications.c.

References ast_register_application_xml, and PARK_APPLICATION.

1009 {
1010  if (ast_register_application_xml(PARK_APPLICATION, park_app_exec)) {
1011  return -1;
1012  }
1013 
1014  if (ast_register_application_xml(PARKED_CALL_APPLICATION, parked_call_app_exec)) {
1015  return -1;
1016  }
1017 
1018  if (ast_register_application_xml(PARK_AND_ANNOUNCE_APPLICATION, park_and_announce_app_exec)) {
1019  return -1;
1020  }
1021 
1022  return 0;
1023 }
#define PARK_APPLICATION
The default parking application that Asterisk expects.
Definition: parking.h:35
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
struct ast_bridge* park_application_setup ( struct ast_channel parkee,
struct ast_channel parker,
const char *  app_data,
int *  silence_announcements 
)

Function to prepare a channel for parking by determining which parking bridge should be used, setting up a park common datastore so that the parking bridge will have access to necessary parking information when joining, and applying various bridge roles to the channel.

Since
12.0.0
Parameters
parkeeThe channel being prepared for parking
parkerThe channel initiating the park; may be the parkee as well. May be NULL.
app_dataarguments supplied to the Park application. May be NULL.
silence_announcementsoptional pointer to an integer where we want to store the silence option flag this value should be initialized to 0 prior to calling park_common_setup.
Returns
reference to a parking bridge if successful
Return values
NULLon failure
Note
ao2_cleanup this reference when you are done using it or you'll cause leaks.

Definition at line 545 of file parking_applications.c.

References RAII_VAR.

547 {
548  int use_ringing = 0;
549  int randomize = 0;
550  int time_limit = -1;
551 
552  RAII_VAR(char *, comeback_override, NULL, ast_free);
553  RAII_VAR(char *, lot_name_app_arg, NULL, ast_free);
554  RAII_VAR(char *, musicclass, NULL, ast_free);
555 
556  if (app_data) {
557  park_app_parse_data(app_data, silence_announcements, &use_ringing, &randomize, &time_limit, &comeback_override, &lot_name_app_arg, &musicclass);
558  }
559 
560  return park_common_setup2(parkee, parker, lot_name_app_arg, comeback_override, musicclass, use_ringing,
561  randomize, time_limit, silence_announcements ? *silence_announcements : 0);
562 
563 }
#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:941
void park_common_datastore_free ( struct park_common_datastore datastore)

Free a park common datastore struct.

Since
12.0.0
Parameters
datastoreThe park_common_datastore being free'd. (NULL tolerant)

Definition at line 335 of file parking_applications.c.

References park_common_datastore::comeback_override, park_common_datastore::parker_dial_string, and park_common_datastore::parker_uuid.

Referenced by get_park_common_datastore_copy().

336 {
337  if (!datastore) {
338  return;
339  }
340 
341  ast_free(datastore->parker_uuid);
342  ast_free(datastore->parker_dial_string);
343  ast_free(datastore->comeback_override);
344  ast_free(datastore);
345 }
struct ast_bridge* park_common_setup ( struct ast_channel parkee,
struct ast_channel parker,
const char *  lot_name,
const char *  comeback_override,
int  use_ringing,
int  randomize,
int  time_limit,
int  silence_announcements 
)

Setup a parked call on a parking bridge without needing to parse appdata.

Since
12.0.0

Definition at line 538 of file parking_applications.c.

541 {
542  return park_common_setup2(parkee, parker, lot_name, comeback_override, NULL, use_ringing, randomize, time_limit, silence_announcements);
543 }
void unload_parking_applications ( void  )

Unregister parking applications.

Since
12.0.0

Definition at line 1025 of file parking_applications.c.

References ast_unregister_application(), and PARK_APPLICATION.

1026 {
1028  ast_unregister_application(PARKED_CALL_APPLICATION);
1029  ast_unregister_application(PARK_AND_ANNOUNCE_APPLICATION);
1030 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define PARK_APPLICATION
The default parking application that Asterisk expects.
Definition: parking.h:35

Variable Documentation

const struct ast_datastore_info park_common_info
static
Initial value:
= {
.type = "park entry data",
.destroy = park_common_datastore_destroy,
}

Definition at line 353 of file parking_applications.c.