Don't give up on attempting an outbound registration if we receive a 408 Timeout.
[asterisk-bristuff.git] / apps / app_flash.c
blob1aa099d71971b482e91b7f6be2be2f5ef4d9c759
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
19 /*! \file
21 * \brief App to flash a zap trunk
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 /*** MODULEINFO
29 <depend>zaptel</depend>
30 ***/
32 #include "asterisk.h"
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <errno.h>
40 #include <sys/ioctl.h>
41 #include <zaptel/zaptel.h>
43 #include "asterisk/lock.h"
44 #include "asterisk/file.h"
45 #include "asterisk/logger.h"
46 #include "asterisk/channel.h"
47 #include "asterisk/pbx.h"
48 #include "asterisk/module.h"
49 #include "asterisk/translate.h"
50 #include "asterisk/image.h"
51 #include "asterisk/options.h"
53 static char *app = "Flash";
55 static char *synopsis = "Flashes a Zap Trunk";
57 static char *descrip =
58 "Performs a flash on a zap trunk. This can be used\n"
59 "to access features provided on an incoming analogue circuit\n"
60 "such as conference and call waiting. Use with SendDTMF() to\n"
61 "perform external transfers\n";
64 static inline int zt_wait_event(int fd)
66 /* Avoid the silly zt_waitevent which ignores a bunch of events */
67 int i,j=0;
68 i = ZT_IOMUX_SIGEVENT;
69 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
70 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
71 return j;
74 static int flash_exec(struct ast_channel *chan, void *data)
76 int res = -1;
77 int x;
78 struct ast_module_user *u;
79 struct zt_params ztp;
80 u = ast_module_user_add(chan);
81 if (!strcasecmp(chan->tech->type, "Zap")) {
82 memset(&ztp, 0, sizeof(ztp));
83 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
84 if (!res) {
85 if (ztp.sigtype & __ZT_SIG_FXS) {
86 x = ZT_FLASH;
87 res = ioctl(chan->fds[0], ZT_HOOK, &x);
88 if (!res || (errno == EINPROGRESS)) {
89 if (res) {
90 /* Wait for the event to finish */
91 zt_wait_event(chan->fds[0]);
93 res = ast_safe_sleep(chan, 1000);
94 if (option_verbose > 2)
95 ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
96 } else
97 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
98 } else
99 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
100 } else
101 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
102 } else
103 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
104 ast_module_user_remove(u);
105 return res;
108 static int unload_module(void)
110 int res;
112 res = ast_unregister_application(app);
114 ast_module_user_hangup_all();
116 return res;
119 static int load_module(void)
121 return ast_register_application(app, flash_exec, synopsis, descrip);
124 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");