Wed Jan 8 2020 09:49:54

Asterisk developer's documentation


app_parkandannounce.c File Reference

ParkAndAnnounce application for Asterisk. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/features.h"
#include "asterisk/say.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int load_module (void)
 
static int parkandannounce_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 = "Call Parking and Announce 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app = "ParkAndAnnounce"
 
static struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

ParkAndAnnounce application for Asterisk.

Author
Ben Miller bgmil.nosp@m.ler@.nosp@m.dccin.nosp@m.c.co.nosp@m.m
  • With TONS of help from Mark!

Definition in file app_parkandannounce.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 233 of file app_parkandannounce.c.

static void __unreg_module ( void  )
static

Definition at line 233 of file app_parkandannounce.c.

static int load_module ( void  )
static

Definition at line 227 of file app_parkandannounce.c.

References ast_register_application_xml, and parkandannounce_exec().

228 {
229  /* return ast_register_application(app, park_exec); */
231 }
static char * app
static int parkandannounce_exec(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int parkandannounce_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 92 of file app_parkandannounce.c.

References __ast_request_and_dial(), ast_channel::_state, args, ARRAY_LEN, AST_APP_ARG, ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_DECLARE_APP_ARGS, ast_exists_extension(), AST_FLAG_IN_AUTOLOOP, AST_FORMAT_SLINEAR, ast_hangup(), ast_log(), ast_masq_park_call(), ast_parseable_goto(), ast_party_id_copy(), ast_party_id_free(), ast_party_id_init(), ast_say_digits(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), ast_verb, ast_waitstream(), ast_channel::caller, ast_channel::context, ast_channel::exten, ast_party_caller::id, ast_channel::language, LOG_WARNING, ast_party_id::name, ast_channel::name, ast_party_id::number, outgoing_helper::parent_channel, ast_channel::priority, S_COR, ast_party_name::str, ast_party_number::str, strsep(), ast_dial::timeout, ast_party_name::valid, ast_party_number::valid, and outgoing_helper::vars.

Referenced by load_module().

93 {
94  int res = -1;
95  int lot, timeout = 0, dres;
96  char *dialtech, *tmp[100], buf[13];
97  int looptemp, i;
98  char *s;
99  struct ast_party_id caller_id;
100 
101  struct ast_channel *dchan;
102  struct outgoing_helper oh = { 0, };
103  int outstate;
105  AST_APP_ARG(template);
106  AST_APP_ARG(timeout);
107  AST_APP_ARG(dial);
108  AST_APP_ARG(return_context);
109  );
110  if (ast_strlen_zero(data)) {
111  ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce_template,timeout,dial,[return_context])\n");
112  return -1;
113  }
114 
115  s = ast_strdupa(data);
117 
118  if (args.timeout)
119  timeout = atoi(args.timeout) * 1000;
120 
121  if (ast_strlen_zero(args.dial)) {
122  ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
123  return -1;
124  }
125 
126  dialtech = strsep(&args.dial, "/");
127  ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
128 
129  if (!ast_strlen_zero(args.return_context)) {
131  ast_parseable_goto(chan, args.return_context);
132  } else {
133  chan->priority++;
134  }
135 
136  ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten,
137  chan->priority,
138  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""));
139  if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority,
140  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
141  ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
142  }
143 
144  /* Save the CallerID because the masquerade turns chan into a ZOMBIE. */
145  ast_party_id_init(&caller_id);
146  ast_channel_lock(chan);
147  ast_party_id_copy(&caller_id, &chan->caller.id);
148  ast_channel_unlock(chan);
149 
150  /* we are using masq_park here to protect * from touching the channel once we park it. If the channel comes out of timeout
151  before we are done announcing and the channel is messed with, Kablooeee. So we use Masq to prevent this. */
152 
153  res = ast_masq_park_call(chan, NULL, timeout, &lot);
154  if (res) {
155  /* Parking failed. */
156  ast_party_id_free(&caller_id);
157  return -1;
158  }
159 
160  ast_verb(3, "Call parked in space: %d, timeout: %d, return-context: %s\n",
161  lot, timeout, args.return_context ? args.return_context : "");
162 
163  /* Now place the call to the extension */
164 
165  snprintf(buf, sizeof(buf), "%d", lot);
166  oh.parent_channel = chan;
167  oh.vars = ast_variable_new("_PARKEDAT", buf, "");
168  dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, chan, args.dial, 30000,
169  &outstate,
170  S_COR(caller_id.number.valid, caller_id.number.str, NULL),
171  S_COR(caller_id.name.valid, caller_id.name.str, NULL),
172  &oh);
174  ast_party_id_free(&caller_id);
175  if (dchan) {
176  if (dchan->_state == AST_STATE_UP) {
177  ast_verb(4, "Channel %s was answered.\n", dchan->name);
178  } else {
179  ast_verb(4, "Channel %s was never answered.\n", dchan->name);
180  ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
181  ast_hangup(dchan);
182  return -1;
183  }
184  } else {
185  ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
186  return -1;
187  }
188 
189  ast_stopstream(dchan);
190 
191  /* now we have the call placed and are ready to play stuff to it */
192 
193  ast_verb(4, "Announce Template:%s\n", args.template);
194 
195  for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
196  if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
197  continue;
198  else
199  break;
200  }
201 
202  for (i = 0; i < looptemp; i++) {
203  ast_verb(4, "Announce:%s\n", tmp[i]);
204  if (!strcmp(tmp[i], "PARKED")) {
205  ast_say_digits(dchan, lot, "", dchan->language);
206  } else {
207  dres = ast_streamfile(dchan, tmp[i], dchan->language);
208  if (!dres) {
209  dres = ast_waitstream(dchan, "");
210  } else {
211  ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
212  }
213  }
214  }
215 
216  ast_stopstream(dchan);
217  ast_hangup(dchan);
218 
219  return res;
220 }
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
Information needed to identify an endpoint in a call.
Definition: channel.h:288
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
char * strsep(char **str, const char *delims)
int priority
Definition: channel.h:841
struct ast_channel * parent_channel
Definition: channel.h:1006
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
struct ast_channel * __ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:5456
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
Definition: channel.c:2095
int ast_say_digits(struct ast_channel *chan, int num, const char *ints, const char *lang)
says digits
Definition: channel.c:8409
void ast_party_id_free(struct ast_party_id *doomed)
Destroy the party id contents.
Definition: channel.c:2141
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_variable * vars
Definition: channel.h:1005
int ast_masq_park_call(struct ast_channel *park_me, struct ast_channel *parker, int timeout, int *extout)
Park a call via a masqueraded channel.
Definition: features.c:1857
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:11326
#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:83
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:5400
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition: channel.c:2087
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
int timeout
Definition: dial.c:49
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static int unload_module ( void  )
static

Definition at line 222 of file app_parkandannounce.c.

References ast_unregister_application().

223 {
225 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static char * app

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call Parking and Announce 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 233 of file app_parkandannounce.c.

char* app = "ParkAndAnnounce"
static

Definition at line 90 of file app_parkandannounce.c.

Definition at line 233 of file app_parkandannounce.c.