Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


app_flash.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, 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 App to flash a DAHDI trunk
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <depend>dahdi</depend>
30  <support_level>core</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
36 
37 #include <dahdi/user.h>
38 
39 #include "asterisk/lock.h"
40 #include "asterisk/file.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/module.h"
44 #include "asterisk/translate.h"
45 #include "asterisk/image.h"
46 
47 /*** DOCUMENTATION
48  <application name="Flash" language="en_US">
49  <synopsis>
50  Flashes a DAHDI Trunk.
51  </synopsis>
52  <syntax />
53  <description>
54  <para>Performs a flash on a DAHDI trunk. This can be used to access features
55  provided on an incoming analogue circuit such as conference and call waiting.
56  Use with SendDTMF() to perform external transfers.</para>
57  </description>
58  <see-also>
59  <ref type="application">SendDTMF</ref>
60  </see-also>
61  </application>
62  ***/
63 
64 static char *app = "Flash";
65 
66 static inline int dahdi_wait_event(int fd)
67 {
68  /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
69  int i,j=0;
70  i = DAHDI_IOMUX_SIGEVENT;
71  if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
72  if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
73  return j;
74 }
75 
76 static int flash_exec(struct ast_channel *chan, const char *data)
77 {
78  int res = -1;
79  int x;
80  struct dahdi_params dahdip;
81 
82  if (strcasecmp(chan->tech->type, "DAHDI")) {
83  ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
84  return -1;
85  }
86 
87  memset(&dahdip, 0, sizeof(dahdip));
88  res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &dahdip);
89  if (!res) {
90  if (dahdip.sigtype & __DAHDI_SIG_FXS) {
91  x = DAHDI_FLASH;
92  res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
93  if (!res || (errno == EINPROGRESS)) {
94  if (res) {
95  /* Wait for the event to finish */
96  dahdi_wait_event(chan->fds[0]);
97  }
98  res = ast_safe_sleep(chan, 1000);
99  ast_verb(3, "Flashed channel %s\n", chan->name);
100  } else
101  ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
102  } else
103  ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
104  } else
105  ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
106 
107  return res;
108 }
109 
110 static int unload_module(void)
111 {
112  return ast_unregister_application(app);
113 }
114 
115 static int load_module(void)
116 {
118 }
119 
120 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
121 
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
static char * app
Definition: app_flash.c:64
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
const char *const type
Definition: channel.h:508
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
Support for translation of data formats. translate.c.
#define LOG_WARNING
Definition: logger.h:144
static int flash_exec(struct ast_channel *chan, const char *data)
Definition: app_flash.c:76
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
#define ast_verb(level,...)
Definition: logger.h:243
General Asterisk channel definitions for image handling.
static int load_module(void)
Definition: app_flash.c:115
General Asterisk PBX channel definitions.
static int unload_module(void)
Definition: app_flash.c:110
Core PBX routines and definitions.
static int dahdi_wait_event(int fd)
Definition: app_flash.c:66
int fds[AST_MAX_FDS]
Definition: channel.h:829
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
int errno
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
struct ast_channel_tech * tech
Definition: channel.h:743
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180